A Brief History of AWS CloudFormation
Back in 2011, AWS decided to make life easier by introducing CloudFormation, a tool that allows engineers to define AWS infrastructure in JSON (or YAML, if you have taste).
Before this, people had to:
- Manually create resources through the AWS Console π΅
- Write long, fragile bash scripts to automate deployments π§
- Cry when their cloud environment wasnβt repeatable π
Feature | CloudFormation | Terraform | Pulumi | Ansible |
---|
AWS-Native | β
Yes | β No | β No | β No |
Multi-Cloud Support | β No | β
Yes | β
Yes | β
Yes |
Language | YAML/JSON | HCL | Python/JS/Go | YAML |
State Management | AWS Managed | Self-managed | Self-managed | No explicit state |
Best For | AWS-only infra | Multi-cloud infra | Devs who prefer real code | Config management |
If youβre all-in on AWS, CloudFormation is a solid choice.
If you need multi-cloud support, Terraform is your best bet.
Pulumi is for devs who hate YAML, and Ansible is for managing software/configurations rather than provisioning infra.
1. Create an S3 Bucket
1
2
3
4
5
6
| AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyS3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: "my-cloudformation-bucket"
|
2. Provision an EC2 Instance
1
2
3
4
5
6
| Resources:
MyEC2Instance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: "t2.micro"
ImageId: "ami-12345678"
|
3. Set Up a VPC
1
2
3
4
5
| Resources:
MyVPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: "10.0.0.0/16"
|
4. Deploy a Load Balancer
1
2
3
4
5
6
| Resources:
MyLoadBalancer:
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Name: "my-load-balancer"
Type: "application"
|
5. Spin Up an RDS Database
1
2
3
4
5
6
7
| Resources:
MyRDS:
Type: "AWS::RDS::DBInstance"
Properties:
Engine: "mysql"
DBInstanceClass: "db.t3.micro"
AllocatedStorage: 20
|
6. Create an IAM Role
1
2
3
4
5
6
7
8
9
10
11
12
| Resources:
MyIAMRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: "MyCloudFormationRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "ec2.amazonaws.com"
Action: "sts:AssumeRole"
|
7. Set Up an Auto Scaling Group
1
2
3
4
5
6
| Resources:
MyAutoScalingGroup:
Type: "AWS::AutoScaling::AutoScalingGroup"
Properties:
MinSize: "1"
MaxSize: "5"
|
8. Deploy a Lambda Function
1
2
3
4
5
6
7
8
| Resources:
MyLambda:
Type: "AWS::Lambda::Function"
Properties:
Runtime: "python3.8"
Handler: "index.lambda_handler"
Code:
S3Bucket: "my-lambda-bucket"
|
9. Create an SNS Topic
1
2
3
4
5
| Resources:
MySNSTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: "My SNS Topic"
|
10. Define a CloudWatch Alarm
1
2
3
4
5
6
7
| Resources:
MyCloudWatchAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmDescription: "High CPU usage"
ComparisonOperator: "GreaterThanThreshold"
Threshold: 80
|
Key Ideas Table
Concept | Explanation |
---|
CloudFormation | AWS-native IaC tool (YAML/JSON) |
State Management | AWS manages state internally |
Best Use Case | Deploying AWS-only infrastructure |
Comparison | Competes with Terraform, Pulumi, and Ansible |
Example Uses | Provisioning VMs, databases, networks, and IAM roles |
Reference Links