Creating and Using Amazon Machine Images (AMI) in AWS EC2
In this lesson, we practiced creating an AMI (Amazon Machine Image) from an EC2 instance to speed up future deployments by pre-installing software. Below is a structured guide covering the key steps.
1. Launching an EC2 Instance
- Choose an OS:
- Select Amazon Linux 2 as the base operating system.
- Instance Type:
- Choose t2.micro (for free tier).
- Key Pair:
- Select an existing key pair (e.g.,
easy-to-draw), though this choice is flexible.
- Network Settings:
- Edit settings to use an existing security group (e.g.,
launch-wizard-1).
- Storage and Advanced Details:
- No storage changes needed.
- In the User Data section, copy all lines except the last one.
- The first lines install Apache HTTPD.
- The last line (which starts the web server) is omitted to avoid immediate execution.
- Launch the Instance.
- Once launched, AWS runs the user data script, installing Apache.
- Even if the instance shows as "running," wait a few minutes for the script to complete before accessing the public IP.
2. Verifying Apache Installation
- After about 2 minutes, access the instance’s public IPv4 address via HTTP.
- If successful, the default Apache test page appears.
3. Creating an AMI from the Instance
- Right-click on the running EC2 instance.
- Select Image and Templates → Create Image.
- Name the image (e.g.,
demo image).
- Leave default settings and click Create Image.