Skip to content

Commit

Permalink
fix(AWS API Gateway): Silence timeout warning for async: true (#8748)
Browse files Browse the repository at this point in the history
  • Loading branch information
MEGApixel23 committed Jan 19, 2021
1 parent e4f368c commit 0384776
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/aws/deploy/lib/extendedValidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
// Check if function timeout is greater than API Gateway timeout
if (functionObject.timeout > 30 && functionObject.events) {
functionObject.events.forEach((event) => {
if (Object.keys(event)[0] === 'http') {
if (Object.keys(event)[0] === 'http' && !event.http.async) {
const warnMessage = [
`WARNING: Function ${functionName} has timeout of ${functionObject.timeout} `,
"seconds, however, it's attached to API Gateway so it's automatically ",
Expand Down
33 changes: 33 additions & 0 deletions test/unit/lib/plugins/aws/deploy/lib/extendedValidate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const AwsProvider = require('../../../../../../../lib/plugins/aws/provider');
const AwsDeploy = require('../../../../../../../lib/plugins/aws/deploy/index');
const Serverless = require('../../../../../../../lib/Serverless');
const { getTmpDirPath } = require('../../../../../../utils/fs');
const runServerless = require('../../../../../../utils/run-serverless');

chai.use(require('sinon-chai'));

Expand Down Expand Up @@ -195,3 +196,35 @@ describe('extendedValidate', () => {
});
});
});

describe('test/unit/lib/plugins/aws/deploy/lib/extendedValidate.test.js', () => {
it("should not warn if function's timeout is greater than 30 and it's attached to APIGW, but it has [async] mode", async () => {
const msg = [
"WARNING: Function foo has timeout of 31 seconds, however, it's",
"attached to API Gateway so it's automatically limited to 30 seconds.",
].join(' ');

const { stdoutData } = await runServerless({
fixture: 'function',
configExt: {
functions: {
foo: {
timeout: 31,
events: [
{
http: {
method: 'GET',
path: '/foo',
async: true,
},
},
],
},
},
},
cliArgs: ['deploy', '--noDeploy'],
});

expect(stdoutData.includes(msg)).to.be.equal(false);
});
});

0 comments on commit 0384776

Please sign in to comment.