Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudFormation create-stack vs deploy

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.

like image 725
nixmind Avatar asked Apr 20 '18 15:04

nixmind


People also ask

What does AWS CloudFormation deploy do?

Instead of independently creating and then initiating a change set, use the aws cloudformation deploy command. When you run this command, it creates a change set, initiates the change set, and then terminates. This command reduces the numbers of required steps when you create or update a stack that includes transforms.

How do I create AWS CloudFormation stack?

To create a stack on the CloudFormation consoleOpen the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . Create a new stack by using one of the following options: Choose Create Stack. This is the only option if you have a currently running stack.

What is the difference between stack and template in CloudFormation?

When you use AWS CloudFormation, you work with templates and stacks. You create templates to describe your AWS resources and their properties. Whenever you create a stack, CloudFormation provisions the resources that are described in your template.

How do you deploy a CloudFormation stack?

Deployment stepsChoose Next, and then on the Specify stack details page, provide the template URL and S3 URI of the parameters file. Choose Next, and continue to choose Next on the subsequent pages until you see the Create Stack option. Choose Create Stack to deploy the stack. Monitor the status of the stack.


2 Answers

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.

like image 64
chris Avatar answered Oct 18 '22 05:10

chris


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.

like image 28
Kirk Broadhurst Avatar answered Oct 18 '22 04:10

Kirk Broadhurst