diff --git a/lib/plugins/aws/package/compile/events/httpApi.js b/lib/plugins/aws/package/compile/events/httpApi.js index 10bc1f1eb..55f209161 100644 --- a/lib/plugins/aws/package/compile/events/httpApi.js +++ b/lib/plugins/aws/package/compile/events/httpApi.js @@ -611,29 +611,29 @@ Object.defineProperties( const functionTimeout = Number(functionData.timeout) || Number(this.serverless.service.provider.timeout) || 6; - if (functionTimeout > 29) { + if (functionTimeout > 30) { logWarning( `Function (${functionName}) timeout setting (${functionTimeout}) is greater than ` + - 'maximum allowed timeout for HTTP API endpoint (29s). ' + + 'maximum allowed timeout for HTTP API endpoint (30s). ' + 'This may introduce a situation where endpoint times out ' + 'for a succesful lambda invocation.' ); log.warning( `Function (${functionName}) timeout setting (${functionTimeout}) is greater than ` + - 'maximum allowed timeout for HTTP API endpoint (29s). ' + + 'maximum allowed timeout for HTTP API endpoint (30s). ' + 'This may introduce a situation where endpoint times out ' + 'for a succesful lambda invocation.' ); - } else if (functionTimeout === 29) { + } else if (functionTimeout === 30) { logWarning( `Function (${functionName}) timeout setting (${functionTimeout}) may not provide ` + - 'enough room to process an HTTP API request (of which timeout is limited to 29s). ' + + 'enough room to process an HTTP API request (of which timeout is limited to 30s). ' + 'This may introduce a situation where endpoint times out ' + 'for a succesful lambda invocation.' ); log.warning( `Function (${functionName}) timeout setting (${functionTimeout}) may not provide ` + - 'enough room to process an HTTP API request (of which timeout is limited to 29s). ' + + 'enough room to process an HTTP API request (of which timeout is limited to 30s). ' + 'This may introduce a situation where endpoint times out ' + 'for a succesful lambda invocation.' ); @@ -642,7 +642,7 @@ Object.defineProperties( // It's a margin needed for some side processing time on AWS side. // Otherwise there's a risk of observing 503 status for successfully resolved invocation // (which just fit function timeout setting) - routeTargetData.timeout = Math.min(functionTimeout + 0.5, 29); + routeTargetData.timeout = Math.min(functionTimeout + 0.5, 30); } }), compileIntegration: d(function (routeTargetData) { diff --git a/test/unit/lib/plugins/aws/package/compile/events/httpApi.test.js b/test/unit/lib/plugins/aws/package/compile/events/httpApi.test.js index ced9d074c..0f00ff60a 100644 --- a/test/unit/lib/plugins/aws/package/compile/events/httpApi.test.js +++ b/test/unit/lib/plugins/aws/package/compile/events/httpApi.test.js @@ -45,6 +45,16 @@ describe('lib/plugins/aws/package/compile/events/httpApi.test.js', () => { handler: 'index.handler', events: [{ httpApi: 'ANY /payload' }], }, + customTimeout: { + handler: 'index.handler', + events: [{ httpApi: 'ANY /custom-timeout' }], + timeout: 29, + }, + maxTimeout: { + handler: 'index.handler', + events: [{ httpApi: 'ANY /max-timeout' }], + timeout: 30, + }, }, }, }).then(({ awsNaming, cfTemplate }) => { @@ -119,11 +129,21 @@ describe('lib/plugins/aws/package/compile/events/httpApi.test.js', () => { expect(resource.Properties.RouteKey).to.equal(routeKey); }); - it('should ensure higher timeout than function', () => { + it('should ensure higher timeout than function default value', () => { const resource = cfResources[naming.getHttpApiIntegrationLogicalId('foo')]; expect(resource.Properties.TimeoutInMillis).to.equal(6500); }); + it('should provide 0.5s time margin to custom function integration timeout', () => { + const resource = cfResources[naming.getHttpApiIntegrationLogicalId('customTimeout')]; + expect(resource.Properties.TimeoutInMillis).to.equal(29500); + }); + + it('should limit function maximum integration timeout to 30s', () => { + const resource = cfResources[naming.getHttpApiIntegrationLogicalId('maxTimeout')]; + expect(resource.Properties.TimeoutInMillis).to.equal(30000); + }); + it('should configure lambda permissions', () => { const resource = cfResources[naming.getLambdaHttpApiPermissionLogicalId('foo')]; expect(resource.Type).to.equal('AWS::Lambda::Permission');