Use CloudFormation to Launch an Amazon EC2 Web Server featuring chatGPT as an AWS Consultant

Tigerine
4 min readMar 13, 2023

The online tutorial for this project can be found here

This project tested my patience and pushed my limits but I went through the hurdles so you can have a smooth ride when doing yours. First thing I need to spell out is that the AWS documentation for this project is a bit incomplete and tad confusing.

In this article, I will state the steps and show you how I went about mine (which was quite different from the documentation)

Step 1: Add and connect resources
Dragging and dropping resources and seeing the JSON/YAML file update in real time felt like a miracle (be sure to select the right dot for each connection). Everything was going fine until I got to step 17 (Drag a connection from the PublicRouteTable resource to the PublicSubnet resource to associate the route table and subnet). Each resource had at least 2 dots (the resource name dot and the depends on dot, some resources had more with different IDs). For some reason, the PublicRouteTable only had a depends on dot making it difficult to establish a direct connection with another resource.
I questioned the architecture I had because it felt like some obvious connections were missing. After a few hours of research and trial and error, I discovered that the final architecture in the sample template was different from the architecture I had after following the steps in the documentation. About 3 connections weren’t stated (WebserverInstance to WebserverSecurityGroup, PublicSubnet to VPC, PublicRouteTable to VPC). See images below to compare

Architecture from tutorial template
Architecture after following the documentation (missing 3 connections)

To solve this, I replicated the sample template in my file and moved to the next step

Step 2: Add parameters, mappings, and outputs

a. Parameters- I copied the JSON snippet as shown in the tutorial. Remember the snippet is a sample so ensure to customize these 3 things: InstanceType description (I used the default), KeyName Description (I used my custom EC2 KeyName) and SSHLocation Description (I used the default)

b. Mappings- The JSON file had a list of mappings for select AWS Regions. Unfortunately, my region wasnt stated so I had to figure out the AMI ID for “HVM64” in my region. I suggest AWS creates a UI on the mappings page where we can just put in the region, value type and automatically generate the AMI ID.
I honestly had no clue how to go about this so I ran to chatGPT to make use of its wisdom. I asked it the question below and it generated a code which I ran on my CMD and it generated the AMI ID for my region.

I deleted the suggested JSON file on the documentation and asked chatGPT to suggest a new JSON file, I then went ahead to customize it with the AMI ID I generated from my CMD (see image below)

My mappings segment (different from what was suggested on the documentation)

c. Outputs- I used the JSON snippet as seen in the documentation

Step 3: Specify resource properties

I followed the steps in the documentation but be sure to specify the properties where needed as seen in instance type, region, key name etc.

Step 4: Provision resources

It was time to provision the resources and know my fate. After clicking Create, all resources successfully created asides the WebServerInstance. I immediately knew I probably didn’t specify it in one of the steps, I scanned through the resource properties and corrected my mistake and BOOM, everything was successfully provisioned and my next step was to marvel at the beauty of Infrastructure As Code (IAC).

Disclaimer: This article describes my personal journey and recommendations made are merely suggestions.
Please feel free to share your thoughts, feedback or criticisms. Look forward to hearing from you

--

--

Tigerine

Just here to express my thoughts and all the chaos that goes on in my head. Baring it all out here so I hope you get to relate with my content.