diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/authorization.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/authorization.js index 62e0acfa6..d295b11ef 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/authorization.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/authorization.js @@ -13,6 +13,15 @@ module.exports = { } if (http.authorizer) { + if (http.authorizer.type && http.authorizer.authorizerId) { + return { + Properties: { + AuthorizationType: http.authorizer.type, + AuthorizerId: http.authorizer.authorizerId, + }, + }; + } + const authorizerLogicalId = this.provider.naming .getAuthorizerLogicalId(http.authorizer.name); diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js index c81ed7edb..e24dc8719 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/method/index.test.js @@ -314,6 +314,32 @@ describe('#compileMethods()', () => { }); }); + it('should set custom authorizer config with authorizeId', () => { + awsCompileApigEvents.validated.events = [ + { + functionName: 'First', + http: { + path: 'users/create', + method: 'post', + authorizer: { + type: 'COGNITO_USER_POOLS', + authorizerId: 'gy7lyj', + }, + }, + }, + ]; + return awsCompileApigEvents.compileMethods().then(() => { + expect( + awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.ApiGatewayMethodUsersCreatePost.Properties.AuthorizationType + ).to.equal('COGNITO_USER_POOLS'); + expect( + awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.ApiGatewayMethodUsersCreatePost.Properties.AuthorizerId + ).to.equal('gy7lyj'); + }); + }); + it('should set authorizer config if given as ARN string', () => { awsCompileApigEvents.validated.events = [ { @@ -322,6 +348,7 @@ describe('#compileMethods()', () => { authorizer: { name: 'Authorizer', }, + integration: 'AWS', path: 'users/create', method: 'post', }, 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 1d7e55b9d..36a272822 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/validate.js @@ -227,6 +227,7 @@ module.exports = { let resultTtlInSeconds; let identityValidationExpression; let claims; + let authorizerId; if (typeof authorizer === 'string') { if (authorizer.toUpperCase() === 'AWS_IAM') { @@ -239,7 +240,10 @@ module.exports = { name = this.provider.naming.extractAuthorizerNameFromArn(arn); } } else if (typeof authorizer === 'object') { - if (authorizer.type && authorizer.type.toUpperCase() === 'AWS_IAM') { + if (authorizer.type && authorizer.authorizerId) { + type = authorizer.type; + authorizerId = authorizer.authorizerId; + } else if (authorizer.type && authorizer.type.toUpperCase() === 'AWS_IAM') { type = 'AWS_IAM'; } else if (authorizer.arn) { arn = authorizer.arn; @@ -284,6 +288,7 @@ module.exports = { type, name, arn, + authorizerId, resultTtlInSeconds, identitySource, identityValidationExpression,