I have two questions about AWS SAM and deployments.
I’m reading through the docs and checking through examples like this and I’m still not quite sure how to deploy to a staging
and production
environment separately with my SAM template. Is it as simple as deploying a new stack with a new name like sam deploy —stack-name my-app-staging
and sam deploy —stack-name my-app-production
?
In the following example, I have one question. If my SAM template contains a Parameters
with the name MyEnvironment
that has three possible values, how does the deploy know which value of the three to use when deploying the stack? Like how would I say to use the value staging
or production
? Is that something that will automatically be asked of me when I deploy or is it something I have to provide on the CLI?
You can use the samconfig.toml
file in order to determine how the stack should be deployed to different environments.
For example:
version = 0.1
[qa.deploy.parameters]
stack_name = "my-qa-stack"
s3_bucket = "XXXXX-qa"
s3_prefix = "XXXXX/qa"
region = "eu-west-1"
capabilities = "CAPABILITY_IAM"
parameter_overrides = "Environment=qa"
[prod.deploy.parameters]
stack_name = "my-prod-stack"
s3_bucket = "XXXXX-prod"
s3_prefix = "XXXXX/prod"
region = "eu-west-1"
capabilities = "CAPABILITY_IAM"
parameter_overrides = "Environment=prod"
You can then pass the required config environment to the command:
sam deploy --config-env <qa|prod>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With