Skip to content

Commit

Permalink
fix(AWS HTTP API): Recognize max timeout as 30s not 29s (#10119)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaioFauza committed Oct 29, 2021
1 parent 7e24669 commit e3e02fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/plugins/aws/package/compile/events/httpApi.js
Expand Up @@ -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.'
);
Expand All @@ -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) {
Expand Down
22 changes: 21 additions & 1 deletion test/unit/lib/plugins/aws/package/compile/events/httpApi.test.js
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit e3e02fe

Please sign in to comment.