AWS Cloud​Formation

AWS CloudFormation is programmable yaml to create AWS resources instead of clicking in AWS console.

  • Define Resources in YAML or JSON, say aws-config.yml
  • Link aws-config.yml to your account, AWS will create all resources based on aws-config.yml.
  • Rollback is possible. Shut everything down is possible.
  • Idempotency: Run same aws-config.yml will not create resources unless aws-config.yml file changed
  • Resource change only apply on affected resources and its friends
  • If you change some resources manually without changing aws-config.yml, CloudFormation will undo your changes because it follows your aws-config.yml
  • Use CloudFormation for things not change often

Structure of aws-config.yml:

AWSTemplateFormatVersion: "2010-09-09"

# Input

# Specify Resources

# Returned resources by this template

CloudFormation Functions

Fn::Select can be shorten as !Select. You can use these functions in CloudFormation yaml.

  • !Sub is string interpolation
  • !GetAttr is to get attribute from resource in template
  • !Ref — Lookup value of a variable
    !Ref "AWS::NoValue"
  • !Select — The intrinsic function Fn::Select returns a single object from a list of objects by index.
  • !Join — The intrinsic function Fn::Join appends a set of values into a single value, separated by the specified delimiter.
  • !Not — Returns true for a condition that evaluates to false or returns false for a condition that evaluates to true.
  • !Equals — Compares if two values are equal.
  • !If — Returns one value if the specified condition evaluates to true and another value if the specified condition evaluates to false.