Day 5: AWS EC2

satyam mishrasatyam mishra
3 min read

Automating EC2 and Saving My Setup Like a Pro

After playing around manually with EC2 for a few days, I started asking myself:

"Can I make the setup part faster?"
"What if I want to reuse this exact setup later?"
"How do people manage multiple instances without losing track?"

So today, I explored a bunch of cool features that answer exactly that.
Let’s go.


1. User Data Scripts – Setting Up EC2 Automatically

Until now, I was SSHing into every new instance and typing commands like:

sudo dnf install httpd -y

Then I discovered User Data scripts. Basically, you can write a script that runs automatically as soon as the instance launches.

Then I discovered User Data scripts. Basically, you can write a script that runs automatically as soon as the instance launches.

Here’s what I tried:

#!/bin/bash
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
echo "<h1>Hello from automated EC2!</h1>" > /var/www/html/index.html

I pasted that into the “User Data” section when launching a new instance, and…
Boom 💥 It just worked. No SSH needed.

I opened the public IP in my browser and the web page was already live.
Game-changer.


2. Creating My Own AMI – Snapshotting My EC2 Setup

After spending so much time tweaking my instance (installing tools, editing configs, etc.), I didn’t want to do it again from scratch.

That’s when I found out I could create an AMI (Amazon Machine Image) of my instance.

Steps:

  • Go to EC2 dashboard

  • Right-click your instance → Create Image

  • Name it something like my-custom-apache-image

  • Done.

Next time I launch an instance, I just select My AMIs and pick it.
It boots with all my stuff — Apache, custom HTML, users, etc.

Huge time saver.


3. Tagging & Organizing EC2 Instances

Once I had 3–4 instances, I started losing track:
“Wait, which one was the NGINX test?” “Where’s my Python server?”

Turns out, tags are the answer.

You can add key-value tags like:

Name: apache-prod
Env: testing
Owner: myname

I added them during launch or later via the EC2 console.
Now I can filter and manage instances cleanly.

Honestly, it made my dashboard look much more professional.


4. Setting Up a Basic Firewall (iptables)

This part was more “Linux” than AWS, but I wanted to try it.

I SSHed into my instance and ran:

sudo iptables -L

It showed default rules. Then I tried adding a basic rule to allow port 80:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

And to block all incoming except SSH and HTTP:

sudo iptables -P INPUT DROP
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

Important note: this can break stuff, so I was careful and kept a second instance as a backup 😅


Key Takeaways Today

  • EC2 User Data made my setup automatic and consistent

  • Creating a custom AMI means I never have to “start from scratch” again

  • Tagging keeps things organized and searchable

  • I got a taste of iptables — which feels super powerful and a bit scary

0
Subscribe to my newsletter

Read articles from satyam mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

satyam mishra
satyam mishra