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 03dcbcfb259..bbafbb75163 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -220,7 +220,11 @@ module.exports = { type = 'AWS_IAM'; } else if (authorizer.arn) { arn = authorizer.arn; - name = this.provider.naming.extractAuthorizerNameFromArn(arn); + if (_.isString(authorizer.name)) { + name = authorizer.name; + } else { + name = this.provider.naming.extractAuthorizerNameFromArn(arn); + } } else if (authorizer.name) { name = authorizer.name; arn = this.getLambdaArn(name); 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 6338005f271..a2132f048e0 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 @@ -934,6 +934,30 @@ describe('#validate()', () => { expect(validated.events[0].http.authorizer.arn).to.equal('xxx:dev-authorizer'); }); + it('should handle an authorizer.arn with an explicit authorizer.name object', () => { + awsCompileApigEvents.serverless.service.functions = { + first: { + events: [ + { + http: { + path: 'foo/bar', + method: 'GET', + authorizer: { + arn: 'xxx:dev-authorizer', + name: 'custom-name', + }, + }, + }, + ], + }, + }; + + const validated = awsCompileApigEvents.validate(); + expect(validated.events).to.be.an('Array').with.length(1); + expect(validated.events[0].http.authorizer.name).to.equal('custom-name'); + expect(validated.events[0].http.authorizer.arn).to.equal('xxx:dev-authorizer'); + }); + it('should throw an error if the provided config is not an object', () => { awsCompileApigEvents.serverless.service.functions = { first: {