Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ functions:
- websocket:
route: $default
authorizer: authorize
- http: GET hello
- http:
path: hello
method: GET
authorizer: authorize
- stream:
type: dynamodb
arn:
Expand Down
9 changes: 8 additions & 1 deletion lib/CfTemplateGenerators/ApiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions serverless-plugin-canary-deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -174,6 +176,7 @@ class ServerlessCanaryDeployments {
return Object.assign(
{},
apiGatewayMethods,
apiGatewayAuthorizers,
apiGatewayV2Methods,
apiGatewayV2Authorizers,
eventSourceMappings,
Expand Down Expand Up @@ -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(
Expand Down