YAML based CloudFormation Templates

AWS CloudFormationAWS CloudFormation is an AWS Management tool that builds infrastructure when passed a template configuration file. When CloudFormation was first announced, the template was pure JSON. On Monday, September 19th, 2016 the AWS Blog announced that the CloudFormation API would now also accept YAML based CloudFormation Templates.

What is YAML?

YAML is now an acronym for “YAML Ain’t Markup Language”. Prior to Jan 3rd, 2002 it was an acronym for “Yet Another Markup Language”. It was renamed because it was more of a data-oriented format than a document markup format.

YAML was designed to be more easily human readable and less verbose than alternatives such as JSON or XML.

What’s Wrong with JSON?

The interpretation of the JSON syntax standard used by AWS in their tools is very strict. Pure JSON does not support comments, and requires both key and values to be in quotes. Brackets are used to denote blocks, with square brackets for arrays and curly brackets for maps (also known as associative arrays or dictionaries).

The lack of comments is a huge problem for users with complex templates containing hundreds of resources. Despite CloudFormation templates being great examples of Infrastructure as Code, it was impossible to include details of the file derived from the source code management system.

Brackets are difficult for humans to process, especially when multiple levels of blocking are used. In order to understand the organization of the template, indentation is almost certainly used. A considerable amount of time is often spent arranging indentation which is irrelevant to the computer.

As a result, technologies such as Troposphere and Terraform were used to ease the management of the management tool!

Why use YAML?

YAML makes use of the indentation that humans naturally use to help organize data. Brackets are no longer necessary. The format is as simple for a beginner to pick up as JSON, but considerably less verbose. It also often provides alternatives syntaxes which might read better.

Name-Value pairs are also known as dictionaries, key-value pairs or maps. In JSON they are defined using curly brackets with the name and value separated with a colon:

{ "a" : 1, "b" : 2, "c" : 3 }

In YAML, the brackets, quotes and commas aren’t required, and newlines delimit items. We end up with:

a : 1
b : 2
c : 3

A list of strings in JSON is defined using quoted, comma-separated values within square brackets:

[ 'a', 'b', 'c' ]

The indentation in JSON isn’t important. In YAML, it could be specified as:

- a
- b
- c


[ a, b, c ]

There are more advanced features of YAML and we look forward to playing with the new YAML CloudFormation templates.


Add Comment

Required fields are marked *. Your email address will not be published.