Cloudformation , AWS::ApiGateway::Deployment not update Api deployment

Ngchiwa Ng
May 8, 2018 · 2 min read

AWS::ApiGateway::Deployment will no update

Recently, we use AWS cloudformation to deploy our api gateway,

we use AWS::Serverless::Function, and AWS::Serverless::Api to deploy our beta stage, it works, and use AWS::ApiGateway::Deployment to prod stage, it only works on first time, and will no update when we deploy agin :(

our template like this:

sam_template_beta.yml //for deploy beta, it will update every time when I deploy

#sam_template_beta.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: api sample
Resources:
lambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: lambdaFunction
AutoPublishAlias: beta
Handler: lambdaFunction.handler
Runtime: nodejs6.10
CodeUri: .
Description: test api
MemorySize: 128
Timeout: 3
Role: '$lambdaRole'
Events:
Api:
Type: Api
Properties:
Path: '/v1/test'
Method: GET
RestApiId: !Ref apiGatewayLogicalName
apiGatewayLogicalName:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: ./swagger.json
StageName: beta
Variables:
env: beta
Outputs:
apiGatewayLogicalNameRestApiId:
Description: ""
Value: !Ref apiGatewayLogicalName
Export:
Name: apiGatewayLogicalNameRestApiId

sam_template_prod.yml //it only works on first deploy, and not update prod stage next time :(

#sam_template_prod.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: api sample
Resources:
apiGatewayProdStage:
Type: "AWS::ApiGateway::Deployment"
Properties:
RestApiId: !ImportValue apiGatewayLogicalNameRestApiId
Description: "prod"
StageName: "prod"

we found, when logical name change, it will deploy stage :), show we change sam_template_prod.yml content

#sam_template_prod.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: api sample
Resources:
apiGatewayProdStage$timestamp: #original apiGatewayProdStage
Type: "AWS::ApiGateway::Deployment"
Properties:
RestApiId: !ImportValue apiGatewayLogicalNameRestApiId
Description: "prod"
StageName: "prod"

great :)

hope this one can help who has AWS::ApiGateway::Deployment can not update issue

Ngchiwa Ng

Backend/iOS Engineer, rock the world

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade