SynfraCore
Synfracore
Start Learning
Navigation

Academies

Platform

RoadmapsLabsCertificationsInterviewPYQsAI AssistantCareer
Start Learning Free🗺️ Learning Roadmaps

CloudFormationAdvanced

Production patterns, performance, security hardening

✍️
Written by senior engineers. Reviewed for technical accuracy.· Updated 2025 · SynfraCore CloudFormation Team
Expert Content

CloudFormation — Advanced

Stack Sets (Multi-Account, Multi-Region)

bash
# Deploy to multiple accounts and regions simultaneously
aws cloudformation create-stack-set \
  --stack-set-name security-baseline \
  --template-body file://security.yaml \
  --permission-model SERVICE_MANAGED \
  --auto-deployment Enabled=true,RetainStacksOnAccountRemoval=false

# Deploy to all accounts in an OU
aws cloudformation create-stack-instances \
  --stack-set-name security-baseline \
  --deployment-targets OrganizationalUnitIds=ou-abc123 \
  --regions ap-south-1 us-east-1 \
  --operation-preferences MaxConcurrentPercentage=25,FailureTolerancePercentage=20

Drift Detection

bash
# Detect if someone manually changed resources outside CloudFormation
aws cloudformation detect-stack-drift --stack-name my-stack
aws cloudformation describe-stack-drift-detection-status --stack-drift-detection-id $ID

# List drifted resources
aws cloudformation describe-stack-resource-drifts \
  --stack-name my-stack \
  --stack-resource-drift-status-filters MODIFIED DELETED

CloudFormation Macros (Transform)

yaml
# AWS::Include macro — embed reusable snippets from S3
Transform: AWS::Include
Parameters:
  Location: s3://my-templates/common-tags.yaml

# SAM Transform (serverless)
Transform: AWS::Serverless-2016-10-31
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.12
      Handler: app.handler
      Events:
        Api:
          Type: Api
          Properties:
            Path: /hello
            Method: get

Best Practices

bash
# Always use change sets in production
aws cloudformation create-change-set \
  --stack-name prod-stack --change-set-name my-changes \
  --template-body file://template.yaml

aws cloudformation describe-change-set \
  --stack-name prod-stack --change-set-name my-changes

# Only execute after reviewing
aws cloudformation execute-change-set \
  --stack-name prod-stack --change-set-name my-changes

# Stack policies prevent accidental deletion
aws cloudformation set-stack-policy --stack-name prod-stack \
  --stack-policy-body '{"Statement":[{"Effect":"Deny","Action":"Update:Delete","Principal":"*","Resource":"*"}]}'
Share:
Join our Community
Daily tips, job alerts, interview help — join engineers learning together
Quick Check — CloudFormation
1 / 1

What is the first step when optimizing a production system?

Up Next
🗺️
CloudFormationRoadmap
Step-by-step structured learning path from zero to expert
Also Worth Exploring
← Back to all CloudFormation modules
IntermediateRoadmap