All about Cloud, mostly about Amazon Web Services (AWS)

YAML based AWS CloudFormation templates

 2016-09-24 /  464 words /  3 minutes

AWS 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. This post explains what YAML is, and why it’s a good alternative to JSON.

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

or

[ a, b, c ]

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


Tags:  AWS  CloudFormation  JSON  YAML
Categories:  AWS  AWS CloudFormation

See Also

 Top Ten Tags

AWS (43)   Kinesis (9)   Streams (8)   AWS Console (5)   Go (5)   Analytics (4)   Data (4)   database (4)   Amazon DynamoDB (3)   Amazon Elastic Compute Cloud (EC2) (3)  


All Tags (173)

Disclaimer

All data and information provided on this site is for informational purposes only. cloudninja.cloud makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. My opinions may change over time.