AWS CloudFormation Cheat Sheet
Template syntax and CLI commands for defining and deploying AWS infrastructure as code with CloudFormation stacks.
2 PagesIntermediateFeb 5, 2026
Basic Template
Minimal template creating an S3 bucket.
yaml
AWSTemplateFormatVersion: '2010-09-09'Description: Simple S3 bucket stackParameters: BucketName: Type: StringResources: MyBucket: Type: AWS::S3::Bucket Properties: BucketName: !Ref BucketNameOutputs: BucketArn: Value: !GetAtt MyBucket.Arn
Intrinsic Functions
Common functions used inside templates.
yaml
# Reference a parameter or resource!Ref MyBucket# Get an attribute of a resource!GetAtt MyBucket.Arn# String substitution!Sub "${AWS::StackName}-bucket"# Join strings!Join ["-", ["prefix", !Ref BucketName]]# Conditional!If [IsProd, "prod-value", "dev-value"]
CLI: Deploy & Manage Stacks
Create, update, and delete stacks.
bash
aws cloudformation deploy \ --template-file template.yaml \ --stack-name my-stack \ --parameter-overrides BucketName=my-unique-bucket \ --capabilities CAPABILITY_IAMaws cloudformation describe-stacks --stack-name my-stackaws cloudformation delete-stack --stack-name my-stackaws cloudformation validate-template --template-body file://template.yaml
Key Concepts
Key key concepts to know.
- Stack- A collection of resources managed together as a single unit
- Change Set- Preview of changes CloudFormation will make before applying an update
- Nested Stack- A stack referenced as a resource inside a parent stack for modularity
- Drift Detection- Identifies resources manually changed outside of CloudFormation
- StackSets- Deploy the same stack across multiple accounts and regions
Template Top-Level Sections
Key template top-level sections to know.
- Parameters- Input values supplied at stack creation/update time
- Mappings- Static key-value lookup tables (e.g. region to AMI ID)
- Conditions- Boolean logic controlling whether resources are created
- Resources- Required section declaring the actual AWS resources
- Outputs- Values exported for use by other stacks or displayed after deploy
Pro Tip
Always run 'aws cloudformation create-change-set' (or use 'deploy', which does this internally) before applying updates to production stacks — reviewing the change set prevents accidental resource replacement or deletion.
Was this cheat sheet helpful?
Explore Topics
#AWSCloudFormation#AWSCloudFormationCheatSheet#CloudComputing#Intermediate#BasicTemplate#IntrinsicFunctions#CLI#Deploy#DataStructures#InfrastructureAsCode#CommandLine#CheatSheet#SkillVeris