As I mentioned in the blog post A Simple Introduction to AWS CloudFormation Part 4: Change Sets = Dry Run Mode CloudFormation Change Sets is the holy grail dry-run feature from the AWS team that allows you to preview your changes before executing them. The feature has actually been around a while but I just did not realized that it was dry-run mode. To use the try Change Set feature, it requires 2 these commands:
- aws cloudformation create-change-set
- aws cloudformation describe-change-set
The output of describe-change-set has a Changes key in the json output which you can review. The usage is pretty awkward. It would be so much easier if you could do everything together in one command.
NOTE: All the source code for this post is available on Github: tongueroo/cloudformation-examples-lono.
Introducing lono cfn preview
I’ve covered lono cfn in Easily Manage CloudFormation Templates with lono cfn. After learning about AWS CloudFormation Change Sets, I was decided to add a dry-run mode to the lono tool. This dry-run command simplifies the usage of change sets to a single command: lono cfn preview 😁
Here is an example of the commands you would have to run before:
$ aws cloudformation create-change-set --stack-name example --template-body file://output/instance-and-route53.yml --parameters file://output/params/stag/instance-and-route53.json --change-set-name changeset-1 $ aws cloudformation describe-change-set --stack-name example --change-set-name changeset-1 $ aws cloudformation describe-change-set --stack-name example --change-set-name changeset-1 | jq '.Changes'
lono cfn takes it all down to one command and also formats the changes in a friendly readable form:
$ lono cfn preview example --template instance-and-route53 ... Generating CloudFormation Change Set for preview..... CloudFormation preview for 'example' stack update. Changes: Add AWS::Route53::RecordSet: DnsRecord $
The output is more human readable than the standard json output from using aws cloudformation describe-change-set. It is also helpfully colorized:
- Green: means the resource is being added
- Yellow: means the resource is being modified
- Red: means the resource is being removed
You should noticed that the preview command also shows you a code diff of the old vs new CloudFormation template that you’re about to upload in additional to the resource changes calculated from Change Sets.
lono cfn update runs preview automatically
Additionally, the lono cfn update command also provides a preview and opportunity to confirm the changes before applying them. It prompts you with a “are you sure” message to confirm. Here is an example:
If you would like to bypass the are you sure prompt, use the –sure flag. For example:
$ lono cfn update example --template instance-and-route53 --sure
More details of lono cfn can be found on it’s README. You can also use lono cfn help.
With the addition of Change Sets, CloudFormation updates can be previewed, reviewed and then applied with higher confidence. It is one of the most exciting changes that I’ve seen to CloudFormation personally. lono cfn preview provides simple usage of AWS CloudFormation Change Sets.
If you enjoyed this post, you might also like these: