AWS CloudFormation
User Guide (API Version 2010-05-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Validating a Template

This section shows you how to validate a AWS CloudFormation template.

To check your template file for syntax errors, you can use the cfn-validate-template command.

Note

The cfn-validate-template command is designed to check only the syntax of your template. It does not ensure that the property values you have specified for a resource are valid for that resource. Nor does it determine the number of resources that will exist when the stack is created.

To check the operational validity, you need to attempt to create the stack. There is no sandbox or test area for AWS CloudFormation stacks, so you are charged for the resources you create during testing.

You can validate templates locally (using the --template-file parameter), or with the --template-url parameter. For example, the following command validates a sample template, from its remote location:

PROMPT> cfn-validate-template --template-url
https://www.fictitious.us/templates/sample.template
--region US-West-1

PARAMETERS  PARAMETER_NAME    DEFAULT_VALUE  NOECHO
PARAMETERS  Email                            false
PARAMETERS  AccessKey                        true
PARAMETERS  VolumeSize        1              false
PARAMETERS  SnapshotId        snap-91f774fb  false
PARAMETERS  SecretKey                        true
PARAMETERS  AvailabilityZone  us-east-1a     false
PARAMETERS  ServerPort        9418           false
PARAMETERS  KeyName                          false
PARAMETERS  InstanceType      m1.small       false

The expected result is no error message, with information about all parameters listed.

Suppose you were editing a local copy of the sample, and you accidentally removed the comma after the ServerPort parameter. Trying to validate it again would result in the following output:

cfn-validate-template:
Malformed input-Template format error: JSON not well-formed.
(line 11, column 6)