1
votes

I am creating a AWS serverless application with SAM. Basically what I would like to achieve is to use API Gateway's different stages (dev/test/prod) to invoke various Lambda functions alias (dev/test/prod).

I am totally stucked, I would like to know what are the strategies people have taken to shift lambda traffics, eg. from LambdaA:dev to LambdaA:prod?

I have tried to use "AutoPublishAlias", but in SAM AutoPublishAlias you can't have more then one alias in a single cloudformation stack, so that makes traffic shifting impossible.

Before using a single stack, I have also used Canary Deployment, it works ok when I separate lambda into multiple envrs (ie. dev-lambaA, test-lambdaA, prod-lambdaA) managed by different cloudformation stack. But I would like to reduce the number of lambda functions by only have lambdas reside in a single stack.

1

1 Answers

0
votes

What you can do is add the following to your template.yaml file:

Resources:
    ProductionAPI:
    Type: AWS::Serverless::Api
        Properties:
        StageName: PRD
        DefinitionUri: ./prdswagger.yaml

    DevelopmentAPI:
    Type: AWS::Serverless::Api
        Properties:
        StageName: DEV
        DefinitionUri: ./devswagger.yaml

And use the swagger files to create your endpoints. At every endpoint add an x-amazon-apigateway-integration to the correct lambda version that you are targeting.

  x-amazon-apigateway-integration:
      httpMethod: "POST"
      type: aws_proxy
      uri: "arn:aws:apigateway:eu-central-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-central-1:[account_nr]:function:[myfunctionname]:PRD/invocations"
      passthroughBehavior: "when_no_match"