Creating a Simple Website using AWS CloudFormation

Shelley Martinez
4 min readMay 3, 2022

--

AWS CloudFormation is a fully-managed service in AWS that allows you to simplify your AWS infrastructure in what we call Infrastructure as Code. CloudFormation allows you to create a template of your AWS resources that you may use for an application and it will configure and provision the resources for you in a “stack”. Having a template with all your resources is beneficial especially if you are replicating the same group of resources in multiple applications or if you have to replicate the same template for multiple regions. Using CloudFormation to organize, manage, and provision your resources will give you a glimpse of CloudFormation’s utilization.

(An AWS User Account is necessary, however, you will be billed for the AWS resources used in creating the template in this article. Delete your stack right away to not incur charges. I used an AWS sandbox.)

To use AWS CloudFormation to host a website we will do the following:

  1. Create a Template with the following resources: VPC, InternetGateway, an InternetGateway Attachment, RouteTable, Public Route, SecurityGroup, LaunchTemplate, and an AutoScalingGroup.
  2. Create a KeyPair in the console
  3. Create a stack in CloudFormation

Template:

A template is a JSON- or YAML-formatted text file that describes your AWS infrastructure. It can be created in Cloud Design, or by using a combination of AWS CloudFormation template snippets of your resources and editing them in your own editor, or you can Google a template that has already been created and edit it for your use case. Personally, Cloud Design did not work well for me in creating my code as it was difficult to follow all the indentations necessary for YAML and also didn’t have a large enough window to scroll through the whole code. The most useful tool in creating my template was AWS Documentation which you will find in the AWS web page, under “Documentation”. Under “Documentation” scroll down to “Management and Governance”, select “User Guide”. Here you will be able to get a deeper dive into CloudFormation. Using AWS CloudFormation template snippets broke down each resource and provided all the possible properties and definitions. This was time consuming for sure, but a great learning tool. Googling CloudFormation templates lead me to some well design code that proved less time consuming. I used a combination of all three to create my stack. I Googled a VPC template with an AutoScaling Group, I copied and pasted it into my text editor, and added a few template snippets from AWS Documentation.

This file contains the code that I used to create a template to upload into my stack:

I have created another medium article explaining the anatomy of a template in more detail here:

Creating the template was the biggest hurdle of this project. Once you have your template, you can begin creating a stack.

Create Stack

In the AWS Console, navigate to CloudFormation and click “Create stack” and choose “With new resources (standard)”:

Copy and Paste Code into Cloud Design and Upload Code

I chose to copy my code and paste it in Cloud Design because it will tell me if I have errors or if it is valid. From here I uploaded my template.

Template is uploaded

Name Stack

Review Parameters which was created in my template:

Continue to accept default settings and complete by selecting “Create stack” and wait…

Here are the resources we created:

--

--