How to use AWS CloudFormation for infrastructure
· Category: Cloud Computing
Short answer
AWS CloudFormation lets you model and provision AWS resources using JSON or YAML templates.
Steps
- Write a template (
template.yaml):
Resources:
MyBucket:
Type: AWS::S3::Bucket
- Create a stack:
aws cloudformation create-stack --stack-name my-stack --template-body file://template.yaml
- Update stacks for changes:
aws cloudformation update-stack ...
- Monitor drift and stack events.
Tips
- Use nested stacks and StackSets for multi-account deployments.
- CloudFormation Guard enforces policy-as-code on templates.
- Drift detection identifies manual resource changes.
Common issues
- Rollback on failure is default; set disable-rollback for debugging.
- Circular dependencies in templates prevent stack creation.