Learn CLOUDFORMATION with Real Code Examples
Updated Nov 27, 2025
Explain
CloudFormation enables Infrastructure-as-Code (IaC) by describing AWS resources and their dependencies declaratively.
Templates are written in JSON or YAML, defining resources, parameters, outputs, and mappings.
CloudFormation automatically provisions and configures resources based on the template.
Supports rollback, drift detection, and stack management for safe deployments.
Integrates with other AWS services like IAM, S3, Lambda, and CodePipeline for complete automation.
Core Features
Stacks - units of deployment
Resources - AWS services defined in templates
Parameters - user input at deployment time
Outputs - exported values from stacks
Mappings, Conditions, and Transform for dynamic behavior
Basic Concepts Overview
Template - JSON or YAML file describing resources
Stack - deployed instance of a template
Change Set - preview changes before updating stack
Resource Types - AWS services and their configurations
Outputs - exported information from stack
Project Structure
Templates folder containing JSON/YAML files
Parameters files (optional) for dynamic values
Nested stacks for modularization
Outputs to share values across stacks
Mappings and conditions for environment-specific settings
Building Workflow
Write CloudFormation template
Validate template using AWS CLI or Console
Create or update a stack from the template
Monitor stack events and status
Use change sets and drift detection for safe updates
Difficulty Use Cases
Beginner: Create a single S3 bucket
Intermediate: Multi-service stack with VPC, EC2, and RDS
Advanced: Nested stacks with cross-stack references
Expert: Multi-account, multi-region deployments with StackSets
Architect: Large-scale enterprise infrastructure automation
Comparisons
CloudFormation vs CDK: CFN is declarative templates, CDK is code-first abstraction
CloudFormation vs Terraform: CFN AWS-native, Terraform is multi-cloud
CloudFormation vs Pulumi: Pulumi is code-first multi-cloud, CFN is declarative AWS-only
CloudFormation vs manual console: CFN is automated and repeatable
CloudFormation vs SAM: SAM is CloudFormation extension for serverless
Versioning Timeline
2011 - AWS CloudFormation initial launch
2012–2015 - Added support for new AWS resources and cross-stack references
2016–2018 - Nested stacks, Change Sets, StackSets
2019–2021 - Drift detection, macros, and enhanced template validation
2022–2025 - Continuous support for new AWS services and resource types
Glossary
Stack - deployed instance of a template
Template - JSON or YAML definition of resources
Change Set - preview of updates to stack
Resource - AWS service configured in a stack
Drift - difference between stack template and deployed resources