DevTools Logo

AWS CloudFormation Cheat Sheet

CloudFormation template structure, resources, parameters, outputs, intrinsic functions, and CLI workflows.

Containers & Cloud
aws
cloudformation
infrastructure

CloudFormation describes AWS infrastructure as declarative JSON or YAML. A template is a set of resources plus optional parameters, mappings, conditions, and outputs that CloudFormation provisions as a single stack.

Template anatomy

yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: Example stack
Parameters:
  InstanceType:
    Type: String
    Default: t3.micro
Resources:
  WebServer:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref InstanceType
      ImageId: ami-0abcdef1234567890
Outputs:
  InstanceId:
    Value: !Ref WebServer
Table
SectionPurpose
AWSTemplateFormatVersionTemplate schema version.
DescriptionHuman-readable summary.
ParametersUser-supplied inputs.
MappingsStatic key/value lookups (e.g. region AMIs).
ConditionsConditional resource creation.
ResourcesThe AWS resources to create (required).
OutputsValues returned after creation.

Intrinsic functions

Table
FunctionYAML shorthandPurpose
Ref!Ref LogicalIdReference a parameter or resource.
GetAtt!GetAtt Resource.AttributeRead a resource attribute.
Sub!Sub "${Bucket}.s3.amazonaws.com"String interpolation.
Join!Join [",", [a, b]]Concatenate values.
Select!Select [0, !Split [",", list]]Pick an element.
FindInMap!FindInMap [Map, Key, Value]Look up a mapping.
ImportValue!ImportValue ExportNameCross-stack reference.

CLI workflows

bash
aws cloudformation validate-template --template-body file://template.yaml
aws cloudformation create-stack --stack-name demo --template-body file://template.yaml
aws cloudformation deploy --stack-name demo --template-file template.yaml --parameter-overrides InstanceType=t3.small
aws cloudformation describe-stacks --stack-name demo
aws cloudformation update-stack --stack-name demo --template-body file://template.yaml
aws cloudformation delete-stack --stack-name demo
Table
CommandPurpose
validate-templateCheck syntax before deploying.
deployCreate or update a stack idempotently.
describe-stack-eventsInspect provisioning progress and failures.
list-stacksEnumerate stacks with status.
delete-stackRemove a stack and its resources.

References