Use ValidateTemplate with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use ValidateTemplate with an AWS SDK or CLI

The following code examples show how to use ValidateTemplate.

CLI
AWS CLI

To validate an AWS CloudFormation template

The following validate-template command validates the sampletemplate.json template:

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

Output:

{ "Description": "AWS 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 AWS resources used if you create a stack from this template.", "Parameters": [], "Capabilities": [] }

For more information, see Working with AWS CloudFormation Templates in the AWS CloudFormation User Guide.

PowerShell
Tools for PowerShell

Example 1: Validates the specified template content. The output details the capabilities, description and parameters of the template.

Test-CFNTemplate -TemplateBody "{TEMPLATE CONTENT HERE}"

Example 2: Validates the specified template accessed via an Amazon S3 URL. The output details the capabilities, description and parameters of the template.

Test-CFNTemplate -TemplateURL https://s3.amazonaws.com/mytemplates/templatefile.template
  • For API details, see ValidateTemplate in AWS Tools for PowerShell Cmdlet Reference.