fix(AWS HTTP API): Recognize max timeout as 30s not 29s (#10119)

This commit is contained in:
Caio Fauza 2021-10-29 06:40:00 -03:00 committed by GitHub
parent 7e246690b5
commit e3e02fe8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -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) {

View File

@ -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');