diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js index bbafbb751..936931cdb 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -78,6 +78,11 @@ module.exports = { http.request = this.getRequest(http); http.request.passThrough = this.getRequestPassThrough(http); http.response = this.getResponse(http); + if (http.integration === 'AWS' && _.isEmpty(http.response)) { + http.response = { + statusCodes: DEFAULT_STATUS_CODES, + }; + } } else if (http.integration === 'AWS_PROXY' || http.integration === 'HTTP_PROXY') { // show a warning when request / response config is used with AWS_PROXY (LAMBDA-PROXY) if (http.request) { diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js index a2132f048..4e481c9d8 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.test.js @@ -1728,4 +1728,54 @@ describe('#validate()', () => { expect(validated.events).to.be.an('Array').with.length(1); expect(validated.events[0].http.request.passThrough).to.equal(undefined); }); + + it('should set default statusCodes to response for lambda by default', () => { + awsCompileApigEvents.serverless.service.functions = { + first: { + events: [ + { + http: { + method: 'GET', + path: 'users/list', + integration: 'lambda', + integrationMethod: 'GET', + }, + }, + ], + }, + }; + + const validated = awsCompileApigEvents.validate(); + expect(validated.events).to.be.an('Array').with.length(1); + expect(validated.events[0].http.response.statusCodes).to.deep.equal({ + 200: { + pattern: '', + }, + 400: { + pattern: '[\\s\\S]*\\[400\\][\\s\\S]*', + }, + 401: { + pattern: '[\\s\\S]*\\[401\\][\\s\\S]*', + }, + 403: { + pattern: '[\\s\\S]*\\[403\\][\\s\\S]*', + }, + 404: { + pattern: '[\\s\\S]*\\[404\\][\\s\\S]*', + }, + 422: { + pattern: '[\\s\\S]*\\[422\\][\\s\\S]*', + }, + 500: { + pattern: + '[\\s\\S]*(Process\\s?exited\\s?before\\s?completing\\s?request|\\[500\\])[\\s\\S]*', + }, + 502: { + pattern: '[\\s\\S]*\\[502\\][\\s\\S]*', + }, + 504: { + pattern: '([\\s\\S]*\\[504\\][\\s\\S]*)|(^[Task timed out].*)', + }, + }); + }); });