In this blog, we'll explore what AWS CloudFormation is, why it's essential, and dive into a practical demonstration to showcase its capabilities.
From understanding the basics to creating your first CloudFormation stack, you'll gain valuable insights and hands-on experience, enabling you to automate your AWS infrastructure management effectively.
Let's explore the AWS CloudFormation and discover how to harness the power of Infrastructure as Code for your projects.
What is AWS CloudFormation?
It is an AWS service that allows you to define and provision AWS infrastructure as code using a template.
The template can be created either using JSON or YAML
When do we use AWS CloudFormation?
When you want to manage and provision your AWS infrastructure in a consistent and repeatable manner.
It allows you to automate the use of AWS services by defining infrastructure as a code.
This approach is particularly valuable in a DevOps environment where you need to create a large infrastructure and you prefer automation over manual things.
You can use AWS CloudFormation in the following scenarios:
Infrastructure as Code
When you want to manage your infrastructure in AWS in a repeatable mannerTemplated Deployment
When you want to create, update, or delete a stack of AWS resources by defining a CloudFormation templateComplex Deployment
For managing multiple AWS resources such as EC2 instances, RDS databases, S3 buckets, and more. CloudFormation helps ensure that all resources are created, configured, and connected correctly.Stack updates
CloudFormation handles updates by creating a change set, which helps prevent disruptions to your existing resources.
Let's understand practically how we can utilize CloudFormation...
For the demo purpose, I'm going to launch two EC2 instances by creating the CloudFormation Template.
Follow the steps for better understanding:
1. Open CloudFormation service in AWS
2. Create a CloudFormation Template file
For creating the template I'm using YAML you can use JSON also
Resources:
NiteshOsUsingCF:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-099b3d23e336c2e83
InstanceType: t2.micro
AvailabilityZone: ap-south-1a
NiteshOs2:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-099b3d23e336c2e83
InstanceType: t2.micro
AvailabilityZone: ap-south-1a
here you can see I'm defining that I want to launch 2 EC2 instances with instance type t2.micro and availability zone as ap-south-1a
You can get the ImageId from the AWS AMI catalog, select the image of your choice, and copy its AMI ID
Note - I'm defining EC2 instances for demo purposes you can define any AWS services like S3, EBS, etc... and their syntax you can check from the docs
To know more about how to create template and syntax you can check the aws doc
here
3. Upload Template to CloudFormation
Make sure your YAML or JSON formatting is correct and the file name is with extension .yml or .json
4. Give a name to your stack
Like here I've given my name as NiteshStack
5. Configure Stack
Configure the stack according to your need
6. Review your stack and click submit
After you review your stack configuration click the submit button
Now you can see the resource creation process is initiated
After a few minutes, you can see the resources are created
Here we can see that new EC2 instances at ap-south-1a are created
If you want to delete your stack you can delete it
Once you delete the stack your resources will be deleted and in our case, the EC2 instances will be deleted
That's how you can utilize AWS CloudFormation service to simplify the Infrastructure Management
Hope you find this blog insightful, Do give it a like 🌟
Thank you!!
Top comments (0)