๐น 1. Launch a Base EC2 Instance
Choose Amazon Linux 2
Select instance type:
t3.microPick any key pair
Use an existing security group
๐น 2. Add User Data (Install Apache Only)
Paste this script โ skip the last line that creates the HTML page:
#!/bin/bash
# Install httpd (Amazon Linux 2)
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpdecho "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html What it does:
Installs Apache (HTTPD)
Starts and enables the service on boot
๐น 3. Wait for Initialization โณ
Instance status = Running โ ready.
User data still runs in the background
Takes ~1โ2 minutes to finish
Then visit:
http://<Public IPv4 address>
โ You should see the Apache default test page
๐งฑ 4. Create Your Custom AMI

Right-click the instance or Select Instance and Click Actions
Go to Image and templates โ Create Image

Name it
demo-image

Keep everything as Default and Click Create Image
Behind the scenes: AWS creates an AMI and an EBS snapshot automatically.
Wait for it:
Go to AMIs
Status moves from โณ Pending โ โ Available

โก 5. Launch a New Instance from the AMI

Click Launch Instance from AMI

Name it From AMI
Go to My AMIs - Owned by me
Select
demo-image

Select key pair or Create new
Select Existing Security Group from Network Setting or Create new
๐น 6. Add Minimal User Data (HTML Only)
Scroll down to bottom
Go to Advanced Details โ User data
Click Launch Instance

#!/bin/bash
# Use this for your user data (script from top to bottom)
# install httpd (Linux 2 version)
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.htmlNotice:
โ No Apache install needed
โ Already baked into the AMI
๐ 7. Result
Wait a few minutes for the instance to finish initializing
Select the instance launched from your AMI
Copy its Public IPv4 address
Paste it into your browser to see the result

๐ฅ Why This Matters
Without AMI | With AMI |
|---|---|
Install Apache every launch โณ | Pre-installed โก |
Slower boot | Instant-ready |
๐งน Cleanup
Delete From AMI instance or any other extra insantaces keep one primary instance only
๐ฏ Key Takeaways
AMIs = pre-configured, reusable environments
Save setup time on every new launch
Improve consistency across instances
Enable fast, repeatable scaling