CloudFormation create stack vs deploy in AWS CLI
CloudFormation provides two options for deploying templates using the AWS CLI:
aws cloudformation create-stack
aws cloudformation deploy
What are the differences between the two?
create-stack
Create stack is a specific API action for creating AWS CloudFormation stacks.
1aws cloudformation create-stack \
2 --stack-name STACK_NAME \
3 --template-body file://path/to/file.json
deploy
Deploy is an abstraction for managing AWS CloudFormation stacks and change sets. The list of API actions available for CloudFormation does not include deploy
.
Unlike create-stack
, which is a direct API call, deploy
combines create-change-set
and execute-change-set
in a single convenient command.
The following command will either create a new stack if one does not exist, or create a change set and execute the change set to update an existing stack.
1aws cloudformation deploy \
2 --stack-name STACK_NAME \
3 --template-body file://path/to/file.json
If the author wants to review the change set before automatically applying, the flag --no-execute-changeset
can be used:
1aws cloudformation deploy \
2 --stack-name STACK_NAME \
3 --template-body file://path/to/file.json \
4 --no-execute-changeset
Should I use create-stack
or deploy
?
In general, aws cloudformation deploy
will be easiest to use. It automatically handles creating or updating change sets on the user’s behalf.