AMI - Amazon Machine Images
What is an AMI?
An AMI (Amazon Machine Image) is a template that contains the software configuration needed to launch an EC2 instance. It's like a "snapshot" or a "disk image" of a complete system.
┌─────────────────────────────────────────────────────────────┐
│ AMI │
├─────────────────────────────────────────────────────────────┤
│ │
│ "An AMI = The DNA of your instance" │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ AMI │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Operating System │ │ │
│ │ │ (Linux, Windows, etc.) │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ System Configuration │ │ │
│ │ │ (users, permissions, etc.) │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Pre-installed Software (optional) │ │ │
│ │ │ (Apache, MySQL, Docker, etc.) │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Storage Configuration │ │ │
│ │ │ (disk size, EBS type) │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ AMI ─────► Instance 1 │
│ └───► Instance 2 (All identical at start) │
│ └───► Instance 3 │
│ │
└─────────────────────────────────────────────────────────────┘
Simple Analogy
┌─────────────────────────────────────────────────────────────┐
│ ANALOGY: AMI = CAKE MOLD │
├─────────────────────────────────────────────────────────────┤
│ │
│ 🧁 BAKERY 💻 AWS │
│ ───────────── ───── │
│ │
│ Cake mold = AMI │
│ (shape, size) (OS, config) │
│ │
│ Produced cakes = EC2 Instances │
│ (all the same) (all identical) │
│ │
│ Decoration after = Post-launch │
│ baking configuration │
│ │
│ One mold → multiple = One AMI → multiple │
│ identical cakes identical instances │
│ │
└─────────────────────────────────────────────────────────────┘
Types of AMIs
1. AWS Public AMIs
Official AMIs provided by Amazon, free (you only pay for the instance).
┌─────────────────────────────────────────────────────────────┐
│ AWS PUBLIC AMIs │
├─────────────────────────────────────────────────────────────┤
│ │
│ Amazon Linux 2023 │
│ ├── Optimized for AWS │
│ ├── Lightweight and performant │
│ ├── Automatic updates │
│ └── Free support via forums │
│ │
│ Amazon Linux 2 (LTS) │
│ ├── Support until 2025 │
│ ├── Very stable │
│ └── Widely documented │
│ │
│ Ubuntu Server │
│ ├── 20.04 LTS, 22.04 LTS, 24.04 LTS │
│ ├── Popular, large community │
│ └── Good for developers │
│ │
│ Red Hat Enterprise Linux (RHEL) │
│ ├── Enterprise support │
│ └── Paid (license included in price) │
│ │
│ Windows Server │
│ ├── 2019, 2022 │
│ └── Windows license included (more expensive) │
│ │
└─────────────────────────────────────────────────────────────┘
2. AWS Marketplace AMIs
AMIs with pre-installed software, often paid (license).
Examples:
• Preconfigured WordPress
• Complete LAMP server
• Jenkins CI/CD
• Splunk
• Palo Alto Firewall
• And thousands more...
💰 Cost = Instance price + Software license price
3. Community AMIs
AMIs created and shared by other AWS users.
⚠️ WARNING:
• Variable quality
• Security not guaranteed
• May contain malware
• Use with caution!
✅ Prefer AMIs from known sources
4. Custom (Private) AMIs
AMIs you create yourself from a configured instance.
┌─────────────────────────────────────────────────────────────┐
│ CUSTOM AMI CREATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. Launch an instance with a base AMI │
│ └── Amazon Linux 2023 │
│ │
│ 2. Configure the instance │
│ └── Install Apache, PHP, MySQL │
│ └── Configure files │
│ └── Add your applications │
│ │
│ 3. Create an AMI from the instance │
│ └── Actions → Image → Create Image │
│ │
│ 4. Use your AMI for new instances │
│ └── All instances will be preconfigured! │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Instance │ → │ AMI │ → │Instances │ │
│ │configured│ │Personal │ │identical │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Components of an AMI
Internal Structure
AMI
├── Root Volume Template
│ └── EBS Snapshot of the root volume
│ └── Operating system
│ └── Installed applications
│
├── Launch Permissions
│ └── Public (everyone)
│ └── Private (your account)
│ └── Shared (specific accounts)
│
├── Block Device Mapping
│ └── Which EBS volumes to attach
│ └── Sizes and types of volumes
│ └── Delete on Termination?
│
└── Metadata
└── Architecture (x86_64, arm64)
└── Virtualization (hvm, pv)
└── Name, description
AMI ID
Format: ami-0123456789abcdef0
Examples:
• ami-0c55b159cbfafe1f0 (Amazon Linux 2 us-east-1)
• ami-0747bdcabd34c712a (Ubuntu 22.04 us-east-1)
⚠️ IMPORTANT: IDs are different by region!
The same "Amazon Linux 2" AMI has a different ID
in us-east-1 and eu-west-1
Comparison of Popular Linux AMIs
| AMI | Use Case | Advantages | Disadvantages |
|---|---|---|---|
| Amazon Linux 2023 | AWS Production | AWS optimized, free | AWS specific |
| Amazon Linux 2 | Legacy, stable | Very stable | End of support 2025 |
| Ubuntu 22.04 LTS | Development | Popular, docs | Slightly heavier |
| Debian | Servers | Very stable | Less AWS support |
| RHEL | Enterprise | Official support | Paid |
| CentOS Stream | RHEL Dev | Free | Less stable than RHEL |
AMI and Regions
┌─────────────────────────────────────────────────────────────┐
│ AMI AND REGIONS │
├─────────────────────────────────────────────────────────────┤
│ │
│ AMIs are REGIONAL! │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ us-east-1 │ │ eu-west-1 │ │
│ │ │ │ │ │
│ │ ami-abc123... │ ≠ │ ami-xyz789... │ │
│ │ (Amazon Linux 2) │ │ (Amazon Linux 2) │ │
│ │ │ │ │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ Same OS, but different ID! │
│ │
│ To use an AMI in another region: │
│ → Copy the AMI (Actions → Copy AMI) │
│ │
│ Personal AMI Copied AMI │
│ us-east-1 ─────────────────► eu-west-1 │
│ ami-abc123 ami-def456 │
│ │
└─────────────────────────────────────────────────────────────┘
Create an AMI (Process)
From an Existing Instance
┌─────────────────────────────────────────────────────────────┐
│ AMI CREATION - STEPS │
├─────────────────────────────────────────────────────────────┤
│ │
│ PREPARATION │
│ 1. Stop the instance (recommended for consistency) │
│ 2. Or create "No reboot" (risk of inconsistency) │
│ │
│ CREATION │
│ 3. Console → EC2 → Instances │
│ 4. Select the instance │
│ 5. Actions → Image and templates → Create image │
│ │
│ CONFIGURATION │
│ 6. Name: "my-app-v1.0" │
│ 7. Description: "Web server with Apache and PHP 8" │
│ 8. Volumes: keep or modify │
│ 9. Tags: add for organization │
│ │
│ WAITING │
│ 10. AMI goes from "pending" to "available" │
│ 11. May take a few minutes │
│ │
│ USAGE │
│ 12. Launch new instances with this AMI │
│ │
└─────────────────────────────────────────────────────────────┘
AWS CLI Command
# Create an AMI from an instance
aws ec2 create-image \
--instance-id i-0123456789abcdef0 \
--name "my-app-v1.0" \
--description "Configured web server" \
--no-reboot
# View your AMIs
aws ec2 describe-images --owners self
# Delete an AMI
aws ec2 deregister-image --image-id ami-0123456789abcdef0
AMI Best Practices
1. Consistent Naming
Recommended format:
<application>-<version>-<date>-<environment>
Examples:
• webapp-v2.1-20241218-prod
• api-server-v1.0-20241218-staging
• bastion-v1.0-20241218-shared
2. Version Your AMIs
webapp-v1.0 → webapp-v1.1 → webapp-v2.0
│ │ │
└── Small └── Bug fix └── New
release feature
3. Automate Creation
┌─────────────────────────────────────────────────────────────┐
│ AUTOMATED AMI PIPELINE │
├─────────────────────────────────────────────────────────────┤
│ │
│ Code ──► Build ──► Test ──► Create AMI ──► Deploy │
│ │ │
│ └── Tool: Packer │
│ │
│ Packer = HashiCorp tool to create AMIs │
│ automatically and reproducibly │
│ │
└─────────────────────────────────────────────────────────────┘
4. Security
✅ TO DO:
• Remove personal SSH keys
• Delete temporary files
• Clear bash history
• Update packages before creation
❌ TO AVOID:
• Plain text passwords in files
• API keys in code
• Unencrypted sensitive data
AMI Cost
┌─────────────────────────────────────────────────────────────┐
│ AMI COST │
├─────────────────────────────────────────────────────────────┤
│ │
│ AMI itself: FREE │
│ │
│ What costs: │
│ • Storage of underlying EBS snapshots │
│ • ~$0.05/GB/month │
│ │
│ Example: │
│ AMI with 20 GB root volume │
│ → Cost: ~$1/month for storage │
│ │
│ Marketplace AMI: │
│ • License cost in addition to storage │
│ • Check price BEFORE launching │
│ │
└─────────────────────────────────────────────────────────────┘
Summary
| Concept | Description |
|---|---|
| AMI | Machine image to launch instances |
| AWS AMI | Official, free, recommended |
| Marketplace AMI | With software, often paid |
| Personal AMI | Created by you, private |
| Regional | Each region has its own AMIs |
| Snapshot | AMI stored as EBS snapshot |
Validation Quiz
- What is an AMI?
- Which Linux AMI is optimized for AWS?
- Are AMIs the same in all regions?
- How to create a custom AMI?
- What costs money with AMIs?
- Why create your own AMIs?
Next section: Instance Types