Reputation: 31
I want to be able to deploy to which stage I want without affecting other stages, for example, I want to deploy all the time to dev, and then deploy to prod without effect the dev stage
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: REGIONAL
StageName: Dev
OpenApiVersion: "3.0"
Name: asaf_api_second
Description: "my api from sam"
if I change the StageName to Prod the stage Dev will delete, how can I prevent that?
Upvotes: 1
Views: 665
Reputation: 21
The required solution includes the following steps:
You will need to define the stage as a parameter in the root level:
Parameters:
stage:
Default: dev
Description: StageName of API Gateway deployment
Type: String
Resources...
Add a reference using (!Ref) to the stage parameter name in the resource definition:
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: REGIONAL
StageName: !Ref stage
OpenApiVersion: "3.0"
Name: asaf_api_second
Description: "my api from sam"
When you want to deploy to prod, override the required stage parameter in the deploy command using cli or in the toml file:
sam deploy --parameter-overrides stage=prod
Upvotes: 1