How to validate CloudFormation template with AWS CLI

September 16, 2016 by Paulina BudzoƄ

Validating your template before uploading it to CloudFormation to create resources is probably the best thing you can do to avoid the dreaded UPDATE_ROLLBACK_IN_PROGRESS status.

This can easily be done without creating the stack, by using the validate-template AWS CLI command.

AWS CLI documentation is not great for examples, so here’s how to validate a template saved as your local file stack.json:

aws cloudformation validate-template --template-body file://stack.json 

(you can also validate a stack template stored inside an S3 bucket and the JSON contents directly).

This will return basic information about the stack (if it’s valid), like Parameters, Description, Capabilities (IAM) needed for the stack, etc.

If your stack template is not correct, you’ll receive an error message specifying what is wrong, for example:

A client error (ValidationError) occurred when calling the ValidateTemplate operation: Template format error: Every Outputs member must contain a Value object

The most important thing to remember about validate-template is that it does not check whether your stack is 100% correct - it only validates the JSON structure, makes sure all parameters are in place, etc. It does not guarantee that the stack will be created successfully. But if it fails, you can be sure that the stack won’t be created at all.

For more information on validate-template call, see:

Posted in: CloudFormation