YAML 101

Key/value pairs

  • YAML document consists of key/value pairs

  • Key/value pairs are separated by colon followed by space

  • Supports different data types

    • Integers

    • Floating-point numbers

    • Strings, enclosed with quotes if they have special symbols

    • Boolean

    • Binary

    • Dates, in ISO:8601 format

    • Null value

Name: Dave
Age: 25
GPA: 4.2
Occupation: Engineer
State: 'New Jersey'
About: "I'm a software engineer"
Score: null
Male: true
DateOfBirth: 1990-09-15T19:07:00

Lists

  • YAML lists are indented with a dash

  • All items are on the same level

  • There are 2 types of writing arrays:

    • Block sequence - each entry indicated with a dash followed by a space

    • Flow sequence - all elements are on the same line, separated with commas and enclosed by [].

Dictionaries

  • A set of properties grouped under an item

  • Dictionaries contain key/value pairs

Lists with Dictionaries

Lists with Dictionaries containing Lists

Pipes

  • Pipe notation is also referred as literal block

  • All new lines, indentation, extra spaces are preserved

Greater than

  • Also referred as folded block

  • Renders the text as a single line

  • All new lines will be replaced with a single space

  • Blank lines are converted to a new line character

Comments

  • Comments are defined with '#' symbol

Anchor / merge

  • Allows to define and reference blocks

  • CloudFormation has very limited support for anchors

Last updated

Was this helpful?