How do I deploy multiple stages using SAM?

I’ve attached an example SAM template below so that you can see how this works in practice.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  sam-app

  Sample SAM Template for sam-app

Globals:
  Function:
    Timeout: 3

Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      OpenApiVersion: '2.0'
      StageName: prod
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.7
      Environment:
        Variables:
          stageName: prod
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
  DevApiStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: dev
      RestApiId: !Ref ApiGatewayApi
      DeploymentId: !Ref ApiGatewayApi.Deployment
  TestApiStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: test
      RestApiId: !Ref ApiGatewayApi
      DeploymentId: !Ref ApiGatewayApi.Deployment
Outputs:
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

No Comments

Leave a Reply