Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I quickly and effectively debug CloudFormation templates?

CloudFormation is a powerful AWS offering that allows the programmatic creation of AWS resource stacks, such as the web tier of an application, a high performance computing cluster, or an entire application stack, with a single API call. It is immensely powerful. Using it is surely considered a good AWS practice, especially when it's combined with Chef, Puppet, or cloud-init. Debugging it drives me to vice.

Take a production example: The stock mongodb cluster templates won't work for me. I don't particularly know why. I'm sure it's something simple as it almost always is. My problem isn't that I can't figure out what's wrong. It's that it takes the stack between 20 and 30 minutes to fail, and then another three or four minutes to delete, assuming it deletes the resources properly at all.

What am I missing? I know about the --disable-rollback flag and use it like oxygen. I learned long ago to wrap exit messages with cfn-signal and to throw them like ballast off a sinking ship. How can I make the template debugging process faster, or am I stuck forever noticing my mistakes half an hour after I make them?

like image 297
Christopher Avatar asked Aug 07 '12 22:08

Christopher


People also ask

How do you debug a CloudFormation?

log or /var/log/cfn-init. log , to help you debug the instance launch. You can retrieve the logs by logging in to your instance, but you must disable rollback on failure or else AWS CloudFormation deletes the instance after your stack fails to create. You can also publish the logs to Amazon CloudWatch.

How do I test a CloudFormation template?

To check your template file for syntax errors, you can use the aws cloudformation validate-template command. The aws cloudformation validate-template command is designed to check only the syntax of your template.


2 Answers

Use the aws cloudformation validate-template command in the AWS CLI tool. It only validates whether your template is valid JSON or YAML, not whether your keys and values are correct (for example doesn't check for typos in keys)

like image 118
Luciano Issoe Avatar answered Oct 13 '22 11:10

Luciano Issoe


Another option, a year later, is to abstract these templates to a 3rd party library, such as troposphere. That library constructs the JSON payload for you, and does a lot of validation along the way. This also solves the "Wow managing a 1000-line JSON file sure is sad" problem.

like image 30
Christopher Avatar answered Oct 13 '22 11:10

Christopher