diff --git a/docs/providers/aws/events/apigateway.md b/docs/providers/aws/events/apigateway.md index ff68cfbc3..8ee5aad0c 100644 --- a/docs/providers/aws/events/apigateway.md +++ b/docs/providers/aws/events/apigateway.md @@ -277,6 +277,7 @@ functions: resultTtlInSeconds: 0 identitySource: method.request.header.Authorization identityValidationExpression: someRegex + type: token authorizerFunc: handler: handler.authorizerFunc ``` @@ -313,6 +314,24 @@ functions: identityValidationExpression: someRegex ``` +You can also use the Request Type Authorizer by setting the `type` property. In this case, you +do not need the `identitySource` + +```yml +functions: + create: + handler: posts.create + events: + - http: + path: posts/create + method: post + authorizer: + arn: xxx:xxx:Lambda-Name + resultTtlInSeconds: 0 + identityValidationExpression: someRegex + type: request +``` + You can also configure an existing Cognito User Pool as the authorizer, as shown in the following example: diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.js index 84b861684..e041f45fb 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.js @@ -37,7 +37,7 @@ module.exports = { '/invocations', ], ] }; - authorizerProperties.Type = 'TOKEN'; + authorizerProperties.Type = authorizer.type ? authorizer.type.toUpperCase() : 'TOKEN'; } _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, { diff --git a/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.test.js b/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.test.js index aa32f062c..c4429362f 100644 --- a/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.test.js +++ b/lib/plugins/aws/package/compile/events/apiGateway/lib/authorizers.test.js @@ -68,6 +68,7 @@ describe('#compileAuthorizers()', () => { resultTtlInSeconds: 500, identitySource: 'method.request.header.Custom', identityValidationExpression: 'regex', + type: 'request', }, }, }]; @@ -92,7 +93,7 @@ describe('#compileAuthorizers()', () => { expect(resource.Properties.IdentityValidationExpression).to.equal('regex'); expect(resource.Properties.Name).to.equal('authorizer'); expect(resource.Properties.RestApiId.Ref).to.equal('ApiGatewayRestApi'); - expect(resource.Properties.Type).to.equal('TOKEN'); + expect(resource.Properties.Type).to.equal('REQUEST'); }); });