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

  1. Write a template (template.yaml):
Resources:
  MyBucket:
    Type: AWS::S3::Bucket
  1. Create a stack:
aws cloudformation create-stack --stack-name my-stack --template-body file://template.yaml
  1. Update stacks for changes:
aws cloudformation update-stack ...
  1. 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.