How to configure AWS Cloud resources using CloudFormation stack

Sunanda Sharma
4 min readMay 28, 2021
CloudFormation working

Cloud Infrastructure resources creation and deletion is a second behavior for a Cloud and DevOps Engineer. While creating resources using AWS UI is very easy and self explanatory process. But if we talk about creating cloud resources at scale, UI certainly is not the right way to do it.

This is when AWS CloudFormation comes into picture. It is a service provided by AWS cloud which takes care of Infrastructure resource management by the use of scripts(JSON or YAML). Using CloudFormation, user can create an entire stack with one function call.

CloudFormation works for all of the AWS resources

There are three ways to create stack using CloudFormation:

1) Template is ready: This way the user already has a template which he can deploy to create the desired infrastructure
2) Using sample template provided by Amazon: There are some templates which are already given to the user by Amazon and can be used as per requirement
3) Create your own template file in the designer: This is an awesome feature from Amazon which allows the user to drag and drop cloud resources and simultaneously creating the JSON/YAML file for those created resources

Now as we know the basic of CloudFormation, lets create a basic stack to program creation of a VPC.

  1. Go to the services section of AWS Console and click on CloudFormation

2. Click on Stack

3. Click on “Template is Ready” and then click on “upload a template”. This template consist of all the YAML code which details the cloud resources to be created

4. You can also view the code by clicking “View in Designer” at the bottom right section.

5. Once the code is ready(code snapshots shown below after steps), specify stack details

6. Review your stack

7. Click ‘Create Stack’

Resources creation in CloudFormation Stack

Above was the process of creating CloudFormation stack from AWS management console. Now lets see what is there in the yaml file that actually creates the cloud resources.

CloudFormation VPC code creation:

  1. Create a VPC

2. Create an Internet Gateway

3. Attach Internet Gateway to VPC

4. Create subnets

5. Create route for the subnet

6. Create Route table for the subnets

7. Create Security Group

8. Create EC2 instance

Please find the full code on this git repository

By and large, it is now very easy to create, manage, and destroy entire application stack with CloudFormation. In a matter of minutes, you know what can go wrong when deploying resources for critical user deployments.

Thanks to CloudFormation :)

--

--