Amazon CloudFormation template formats - 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 (PDF).

Amazon CloudFormation template formats

You can author Amazon CloudFormation templates in JSON or YAML formats. We support all Amazon CloudFormation features and functions for both formats, including in Amazon CloudFormation Designer.

When deciding which format to use, pick the format that you're most comfortable working in. Also consider that YAML inherently provides some features, such as commenting, that aren't available in JSON.

Important

We recommend that you don't add # YAML comments to your templates in Designer. If your YAML template has # comments, Designer doesn't preserve those comments when converting the template to JSON. In addition, if you modify your template in Designer (for example, if you move a resource on the canvas), your comments are lost.

You can add comments to the Amazon CloudFormation templates you create outside of Designer. The following example shows a YAML template with inline comments.

AWSTemplateFormatVersion: "2010-09-09" Description: A sample template Resources: MyEC2Instance: #An inline comment Type: "AWS::EC2::Instance" Properties: ImageId: "ami-0ff8a91507f77f867" #Another comment -- This is a Linux AMI InstanceType: t2.micro KeyName: testkey BlockDeviceMappings: - DeviceName: /dev/sdm Ebs: VolumeType: io1 Iops: 200 DeleteOnTermination: false VolumeSize: 20

For more information about the template syntax for each format, see Template anatomy.

Amazon CloudFormation supports the following JSON and YAML specifications:

JSON

Amazon CloudFormation follows the ECMA-404 JSON standard. For more information about the JSON format, see http://www.json.org.

YAML

Amazon CloudFormation supports the YAML Version 1.1 specification with a few exceptions. Amazon CloudFormation doesn't support the following features:

  • The binary, omap, pairs, set, and timestamp tags

  • Aliases

  • Hash merges

For more information about YAML, see https://yaml.org/.