diff --git a/example/serverless.yml b/example/serverless.yml index fbf53b9..7a33c46 100644 --- a/example/serverless.yml +++ b/example/serverless.yml @@ -33,7 +33,10 @@ functions: - websocket: route: $default authorizer: authorize - - http: GET hello + - http: + path: hello + method: GET + authorizer: authorize - stream: type: dynamodb arn: diff --git a/lib/CfTemplateGenerators/ApiGateway.js b/lib/CfTemplateGenerators/ApiGateway.js index f5b02be..4d2309f 100644 --- a/lib/CfTemplateGenerators/ApiGateway.js +++ b/lib/CfTemplateGenerators/ApiGateway.js @@ -42,10 +42,17 @@ function replaceV2AuthorizerUriWithAlias (apiGatewayMethod, functionAlias) { return newMethod } +function replaceAuthorizerUriWithAlias (apiGatewayMethod, functionAlias) { + const aliasUri = buildUriForAlias(functionAlias) + const newMethod = _.set('Properties.AuthorizerUri', aliasUri, apiGatewayMethod) + return newMethod +} + const ApiGateway = { replaceV2IntegrationUriWithAlias, replaceMethodUriWithAlias, - replaceV2AuthorizerUriWithAlias + replaceV2AuthorizerUriWithAlias, + replaceAuthorizerUriWithAlias } module.exports = ApiGateway diff --git a/serverless-plugin-canary-deployments.js b/serverless-plugin-canary-deployments.js index d206203..2254278 100644 --- a/serverless-plugin-canary-deployments.js +++ b/serverless-plugin-canary-deployments.js @@ -142,6 +142,7 @@ class ServerlessCanaryDeployments { const replaceAliasStrategy = { 'AWS::Lambda::EventSourceMapping': CfGenerators.lambda.replaceEventMappingFunctionWithAlias, 'AWS::ApiGateway::Method': CfGenerators.apiGateway.replaceMethodUriWithAlias, + 'AWS::ApiGateway::Authorizer': CfGenerators.apiGateway.replaceAuthorizerUriWithAlias, 'AWS::ApiGatewayV2::Integration': CfGenerators.apiGateway.replaceV2IntegrationUriWithAlias, 'AWS::ApiGatewayV2::Authorizer': CfGenerators.apiGateway.replaceV2AuthorizerUriWithAlias, 'AWS::SNS::Topic': CfGenerators.sns.replaceTopicSubscriptionFunctionWithAlias, @@ -162,6 +163,7 @@ class ServerlessCanaryDeployments { getEventsFor (functionName) { const apiGatewayMethods = this.getApiGatewayMethodsFor(functionName) + const apiGatewayAuthorizers = this.getApiGatewayAuthorizersFor(functionName) const apiGatewayV2Methods = this.getApiGatewayV2MethodsFor(functionName) const apiGatewayV2Authorizers = this.getApiGatewayV2AuthorizersFor(functionName) const eventSourceMappings = this.getEventSourceMappingsFor(functionName) @@ -174,6 +176,7 @@ class ServerlessCanaryDeployments { return Object.assign( {}, apiGatewayMethods, + apiGatewayAuthorizers, apiGatewayV2Methods, apiGatewayV2Authorizers, eventSourceMappings, @@ -214,6 +217,20 @@ class ServerlessCanaryDeployments { return getMethodsForFunction(this.compiledTpl.Resources) } + getApiGatewayAuthorizersFor (functionName) { + const isApiGMethod = _.matchesProperty('Type', 'AWS::ApiGateway::Authorizer') + const isMethodForFunction = _.pipe( + _.prop('Properties.AuthorizerUri'), + flattenObject, + _.includes(functionName) + ) + const getMethodsForFunction = _.pipe( + _.pickBy(isApiGMethod), + _.pickBy(isMethodForFunction) + ) + return getMethodsForFunction(this.compiledTpl.Resources) + } + getApiGatewayV2AuthorizersFor (functionName) { const isApiGMethod = _.matchesProperty('Type', 'AWS::ApiGatewayV2::Authorizer') const isMethodForFunction = _.pipe(