AWS CloudFormation Essentials

AWS Logo

AWS CloudFormation Essentials

CloudFormation templates can be defined using YAML or JSON

AWS Logo

CloudFormation Components

CloudFormation consists of 9 components. Only Resources is mandatory

  1. AWSTemplateFormatVersion:
    Future proofs the template from future features and behaviors of CloudFormation. Or if the format of the template changes.
  2. Description:
    Optional however it must come right after AWSTemplateFormatVersion if you intend to use it.
  3. Metadata:
    Optional multipurpose.
  4. Parameters:
    Define inputs
  5. Mappings:
    Include conditional data
  6. Conditions:
    Similar to a switch IF statement
  7. Transform:
    Mainly used in serverless applications
  8. Resources:
    Only required component.
    Here logical resources are define which translate into physical resources once the template has been executed.
    If you do not utilize the Name parameter of a logical resource it will incorporate the logic resources name.
  9. Outputs:

CloudFormation Skeleton

YAML

---
AWSTemplateFormatVersion: "2010-09-09"

Description:
  this template does something

Metadata:
  template metadata

Parameters:
  set of parameters

Mappings:
  set of mappings

Conditions:
  set of conditions

Transform:
  set of transforms

Resources:
  set of resources

Outputs:
  set of outputs

JSON

{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "this template does something",

  "Metadata" : {

  },

  "Parameters" : {

  },

  "Mappings" : {

  },

  "Conditions" : {

  },

  "Transform" : {

  },

  "Resources" : {

  },

  "Outputs" : {

  }
}

Intrinsic Functions

Functions that assist in assigning values to properties that are not available until runtime.

Fn:GetAZs

Fn:Base64

Fn:Cidr

Fn:FindInMap

Fn:GetAtt

Fn:ImportValue

Fn:Join

Fn:Select

Fn:Split

Fn:Sub

Fn:Transform

Ref

Condition Functions

Conditional create stack resources

Fn:And

Fn:Equals

Fn:If

Fn:Not

Fn:Or

  • https://aws.amazon.com/cloudformation/
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/CHAP_TemplateQuickRef.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html