Validating a template - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Validating a template

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

Note

The aws cloudformation validate-template command is designed to check only the syntax of your template. It does not ensure that the property values that 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 Amazon CloudFormation stacks, so you are charged for the resources you create during testing.

During validation, Amazon CloudFormation first checks if the template is valid JSON. If it isn't, CloudFormation checks if the template is valid YAML. If both checks fail, CloudFormation returns a template validation error. You can validate templates locally by using the --template-body parameter, or remotely with the --template-url parameter.

Valid template

The following example passes the --template-url parameter, to validate a template in a remote location:

aws cloudformation validate-template --template-url https://s3.amazonaws.com/cloudformation-templates-us-east-1/S3_Bucket.template

The following is the output of the previous command.

{
    "Description": "Amazon CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket.
You will be billed for the Amazon resources used if you create a stack from this template.",
    "Parameters": [],
    "Capabilities": []
}

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

Validation error

This section produces a validation error when running the aws cloudformation validate-template command.

The following example passes the --template-body parameter, to validate a template locally.

aws cloudformation validate-template --template-body file:///home/local/test/sampletemplate.json

The following is the output of the previous command.

{
    "ResponseMetadata": {
        "RequestId": "4ae33ec0-1988-11e3-818b-e15a6df955cd"
    },
    "Errors": [
        {
            "Message": "Template format error: JSON not well-formed. (line 11, column 8)",
            "Code": "ValidationError",
            "Type": "Sender"
        }
    ],
    "Capabilities": [],
    "Parameters": []
}
A client error (ValidationError) occurred: Template format error: JSON not well-formed. (line 11, column 8)

The expected result is an error message, with information about error listed.