Template formats
You can author CloudFormation templates in JSON or YAML formats. The same CloudFormation features and functions are available for both formats.
JSON
The following example shows the structure of a JSON-formatted template with all available sections.
{ "AWSTemplateFormatVersion" : "
version date
", "Description" : "JSON string
", "Metadata" : {template metadata
}, "Parameters" : {set of parameters
}, "Rules" : {set of rules
}, "Mappings" : {set of mappings
}, "Conditions" : {set of conditions
}, "Transform" : {set of transforms
}, "Resources" : {set of resources
}, "Outputs" : {set of outputs
} }
YAML
The following example shows the structure of a YAML-formatted template with all available sections.
--- AWSTemplateFormatVersion: "
version date
" Description:String
Metadata:template metadata
Parameters:set of parameters
Rules:set of rules
Mappings:set of mappings
Conditions:set of conditions
Transform:set of transforms
Resources:set of resources
Outputs:set of outputs
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.
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
Specifications
CloudFormation supports the following JSON and YAML specifications:
- JSON
-
CloudFormation follows the ECMA-404 JSON standard. For more information about the JSON format, see http://www.json.org
. - YAML
-
CloudFormation supports the YAML Version 1.1 specification with a few exceptions. CloudFormation doesn't support the following features:
-
The
binary
,omap
,pairs
,set
, andtimestamp
tags -
Aliases
-
Hash merges
For more information about YAML, see https://yaml.org/
. -
Learn more
For each resource you specify in your template, you define its properties and values using the specific syntax rules of either JSON or YAML. For more information about the template syntax for each format, see Template sections.