Nuts and Bolts

Everyone has opinions and thoughts. Here are some of ours.

AWS CloudFormation dry-run with lono cfn preview

Posted by Tung Nguyen
on
Apr 23, 2017

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.

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 😁

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.

Summary

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.