AWS Hands-On | EC2 Instance Storage | AMI Creation Process
📌 Notice
This is a hands-on tutorial accompanying the blog post:
🔹 Focus: Practical implementation of EC2 AMI Creation.
🔹 For theoretical concepts and exam-style questions, please refer to the main blog post (link to parent blog).
Here’s a step-by-step explanation of the AMI creation process from an existing EC2 instance using the AWS Management Console
1. Launch a New EC2 Instance (If Target Instance Doesn’t Exist)
AWS Console Steps:
1. Go to the EC2 Dashboard
- Log in to the AWS Management Console
- Navigate to Services > EC2
2. Launch an Instance
- Click “Launch Instance”
- Enter a name for your instance (e.g.,
AMI-Source-Server
) - Choose an Amazon Machine Image (AMI)
- Select an OS (e.g., Amazon Linux, Ubuntu, Windows)
- Choose an AMI (Free Tier eligible if applicable)
- Select an Instance Type
Note :
For testing,t2.micro
(Free Tier eligible)
For production, choose a suitable type (e.g.,t3.medium
,m5.large
)
- Configure Key Pair (for SSH Access)
- Select an existing key pair or create a new one
- Download the
.pem
file (required for Linux SSH access) - Network Settings (Security Group)
- Select a VPC and subnet (default is fine for testing)
- Configure Security Group:
- Allow SSH (Port 22) for Linux
- Allow RDP (Port 3389) for Windows
- Add HTTP (Port 80) if it’s a web server
- Configure Storage
- Default root volume (usually 8GB for Linux, 30GB for Windows)
- Add additional EBS volumes if needed
- Click “Launch Instance”
- Wait for the instance to reach the “Running” state
2. Connect & Customize the EC2 Instance
Step 1: Locate Your .pem
Key File
For Linux (SSH)
- Your key is saved in the Downloads folder (unless you chose a different location).
- On Linux/macOS, it’s typically at:
~/Downloads/AMI-Source-Server-Key.pem
Step 2: Set Correct Permissions (Linux/macOS Only)
For security, SSH requires the .pem
file to have restricted permissions. Run:
chmod 400 ~/Downloads/AMI-Source-Server-Key.pem
Step 3: Find Your EC2 Instance’s Public IP
- Go to AWS EC2 Dashboard > Instances
- Select your instance
- Copy the Public IPv4 address (e.g.,
47.129.46.47
)
Step 4: Run the SSH Command
ssh -i ~/Downloads/AMI-Source-Server-Key.pem ec2-user@47.129.46.47
Customizations (Examples)
- Install software (
sudo yum install -y nginx
for Amazon Linux) - Copy application files
- Configure users, permissions, and services
- Apply security patches (
sudo yum update -y
)
3. Stop the Instance for Data Integrity
- Go to EC2 Dashboard > Instances
- Select your instance
- Click “Instance State” > “Stop Instance” (not reboot)
4. Create an AMI (with EBS Snapshots)
- Select the stopped instance
- Click Actions > Image and templates > Create image
3. Configure:
- Name:
my-custom-ami-v1
- Description: (Optional)
- No reboot: Unchecked (since we stopped it manually)
- Click “Create Image”
AWS will:
- Create snapshots of all attached EBS volumes
- Register the AMI (visible in AMIs > Owned by me)
5. Launch New Instances from the AMI
- Go to EC2 > AMIs
- Select your custom AMI
- Click “Launch instance from AMI”
- Follow the standard EC2 launch process
6. Copy AMI and Launch EC2 in Another Region
Cleanup (Optional)
- Deregister AMI: EC2 > AMIs > Select AMI > Actions > Deregister
- Delete Snapshots: EC2 > Snapshots > Select associated snapshots > Delete