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
| Section | Purpose |
|---|---|
AWSTemplateFormatVersion | Template schema version. |
Description | Human-readable summary. |
Parameters | User-supplied inputs. |
Mappings | Static key/value lookups (e.g. region AMIs). |
Conditions | Conditional resource creation. |
Resources | The AWS resources to create (required). |
Outputs | Values returned after creation. |
Intrinsic functions
Table
| Function | YAML shorthand | Purpose |
|---|---|---|
| Ref | !Ref LogicalId | Reference a parameter or resource. |
| GetAtt | !GetAtt Resource.Attribute | Read 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 ExportName | Cross-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
| Command | Purpose |
|---|---|
validate-template | Check syntax before deploying. |
deploy | Create or update a stack idempotently. |
describe-stack-events | Inspect provisioning progress and failures. |
list-stacks | Enumerate stacks with status. |
delete-stack | Remove a stack and its resources. |