Automate AWS infrastructure using CloudFormation and YAML templates to deploy EC2, S3, and RDS with Infrastructure as Code (IaC).
In this project, I used AWS CloudFormation to automate and manage cloud infrastructure. Instead of manually creating resources, I wrote templates in YAML format and deployed EC2, S3, and RDS automatically. Below is the step-by-step process I followed.
📄 Template Used: my-cloudformation-template.yaml
First, I created a simple YAML file (template) that includes definitions for:
- EC2 Instance
- S3 Bucket
- RDS Database (MySQL)
📁 File Name: my-cloudformation-template.yaml
# my-cloudformation-template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: "Deploy EC2, S3, and RDS using CloudFormation"
Resources:
MyS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-cloudformation-s3-bucket-vishwaraj-0413 # Replace with your S3 Bucket name
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-080b1a55a0ad28c02 # Amazon Linux 2 AMI (check for your region)
InstanceType: t2.micro
KeyName: test-key # Replace with your EC2 key pair name
SecurityGroups:
- default
MyRDSInstance:
Type: AWS::RDS::DBInstance
Properties:
DBInstanceIdentifier: mydbinstance
AllocatedStorage: 20
DBInstanceClass: db.t3.micro
Engine: MTSQL
MasterUsername: adminuser
MasterUserPassword: mysecurepassword
PubliclyAccessible: true
Figure: CloudFormation Template Yaml Code
- Go to AWS Console → CloudFormation
- Click "Create stack" → "With new resources (standard)"
- Choose "Upload a template file"
- Upload the YAML file
- Click Next
Figure: Create stack and Upload a YAML template file
- Stack Name: my-infra-stack
- ClickNext (keep default settings)
Figure: Configure Stack Details
- Review all resources listed
- Click Create stack
Figure: Review and Launch Stack
- Stack status will show as CREATE_IN_PROGRESS
- After a few minutes, it changes to CREATE_COMPLETE
Figure: Stack Creation Status Check
I verified the resources in their respective AWS services:
- EC2 Instance → Go to EC2 → Instances
Figure: EC2 Instance Create Successfully
- S3 Bucket → Go to S3 → Buckets
Figure: S3 Bucket Create Successfully
- RDS Database → Go to RDS → Databases
Figure: RDS Database Create Successfully
Later, I updated my template to change the EC2 instance type and re-deployed it using Update Stack option in CloudFormation.
Figure: Stack Update Complete Successfully
After testing, I deleted the entire stack using Delete Stack option — this automatically deleted all the resources created by the template.
Figure: Resources Delete in progress
Figure: Resources Delete Complete
In this project, I used AWS CloudFormation to automate the deployment of resources like EC2, S3, and RDS. This allowed me to manage infrastructure with Infrastructure as Code (IaC), ensuring consistency, scalability, and easier updates. The project helped me understand the power of automation in cloud environments and gave me hands-on experience in managing and troubleshooting cloud resources efficiently.
- I used YAML syntax for better readability.
- The entire infrastructure is now version-controlled and can be reused or shared easily.
- It saves time, reduces manual errors, and follows best practices for DevOps.
Vishwaraj Kumar
🔗 GitHub Profile
🔗 LinkedIn Profile
