CloudFormation create stack vs deploy in AWS CLI

CloudFormation provides two options for deploying templates using the AWS CLI:

  1. aws cloudformation create-stack
  2. aws cloudformation deploy

What are the differences between the two?

create-stack

Create stack is a specific API action for creating AWS CloudFormation stacks.

1
2
3
aws cloudformation create-stack \
    --stack-name STACK_NAME \
    --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.

1
2
3
aws cloudformation deploy \
    --stack-name STACK_NAME \
    --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:

1
2
3
4
aws cloudformation deploy \
    --stack-name STACK_NAME \
    --template-body file://path/to/file.json \
    --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.