35
votes

Can someone clearly explain to me difference and precedence between AWS CLI Cloudformation create-stack and deploy commands? For me it seems like they do same thing and deploy resources.

Why when you run the deploy command from the cli, the create stack has no executable change set, while the documenation says :

Deploys the specified AWS CloudFormation template by creating and then executing a change set. The command terminates after AWS CloudFormation executes the change set. If you want to view the change set before AWS CloudFormation executes it, use the --no-execute-changeset flag.

2

2 Answers

37
votes

create-stack can only be used when you know you want to create a new stack. If you want to update a stack, you have to use a different command, etc. If you're writing (ug) batch files to help run your cloudformation, this can be a real pain.

The deploy is functionality to better take advantage of change sets - rather than having to know if a stack exists, you can simply run deploy and the tool will figure out what it needs to do. With the --no-execute-changeset, it will actually provide you the command needed if you decide you want to review the changes before applying them.

It looks like this was introduced in Nov. 2016, probably around the time change sets were released.

13
votes

I assume that deploy is just 'syntactic sugar' around the CreateChangeSet, CreateStack, and UpdateStack api methods.

Note that although deploy is in the CLI, it is not in the API reference.

I assume that deploy is preferred outside of any need to explicitly review a change set. Without using deploy you would potentially need to create-change-set then decide whether to create or update a stack. In this case, deploy is like a stack "upsert".


I stopped being lazy and checked the code, and yes - deploy is ultimately a nicer way of using cloudformation from the CLI. The implementation is here and here. Note that as of today the ability to control rollback behaviour doesn't existing for deploy per this issue.