CloudFormation Basics
Define and deploy AWS infrastructure as code with CloudFormation stacks.
CloudFormation is AWS’s native IaC service. You write a template (YAML or JSON) describing resources, and CloudFormation provisions them as a stack — a single managed unit you can update or delete together.
Template sections: Parameters (inputs), Resources (the actual infrastructure, required), Mappings/Conditions (logic), and Outputs (exported values). Change sets preview what an update will do before you apply it, and CloudFormation rolls back automatically if a deployment fails.
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
BucketName:
Type: String
Resources:
AppBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Ref BucketName
VersioningConfiguration:
Status: Enabled
Outputs:
BucketArn:
Value: !GetAtt AppBucket.Arnaws cloudformation deploy --template-file s3.yaml \
--stack-name my-bucket --parameter-overrides BucketName=my-unique-bucket - Identify the required section of a CloudFormation template.
- Add a parameter and reference it with
!Ref. - Explain what a change set is used for.
- Describe what happens to resources when you delete a stack.
Cheat Sheet▾
| Section | Purpose |
|---|---|
| Parameters | Inputs to the template |
| Resources | Infrastructure (required) |
| Mappings/Conditions | Logic/lookups |
| Outputs | Exported values |
| Stack | Deployed unit of resources |
| Change set | Preview an update |
!Ref / !GetAtt | Reference params/attributes |
Common Interview Questions▾
What is a CloudFormation stack?
The collection of AWS resources created from a single template, managed as one unit — you create, update, or delete them together, with automatic rollback on failure.
What is a change set?
A preview of the changes a stack update would make before you execute it, so you can review additions, modifications, and deletions and avoid surprises.