Chapter 14: EC2 Operations — Elastic IP, AMI, Snapshots and Vertical Scaling
14.2 AMI (Amazon Machine Image)
In short: An AMI is a template used to launch instances.
What is an AMI?
An AMI is a template used to launch instances. It is made of:
| Part | Meaning |
|---|---|
| Root volume snapshot(s) | EBS snapshot of the OS disk (plus any extra data volumes included) |
| Block device mapping | Which volumes to create at launch, their sizes, types and device names |
| Launch permissions | Who can use it: only your account, specific accounts, or public |
| Metadata | Architecture (x86_64/arm64), virtualization, boot mode, ENA support, description |
In simple words, an AMI is like a "photocopy master" of a fully set-up computer — every instance launched from it starts as an exact copy. Technically, launching from an AMI creates new EBS volumes from its snapshots according to the block device mapping.
| AMI type | Provided by | Examples |
|---|---|---|
| AWS/Quick Start | AWS and OS vendors | Amazon Linux 2023, Ubuntu 24.04, Windows Server |
| AWS Marketplace | Software vendors (may include software charges) | Hardened OS images, WordPress by vendors, firewalls |
| Community AMIs | Anyone who made an AMI public | CentOS Stream images, custom builds (verify the publisher!) |
| My AMIs | You | Your own configured web server |
Create an AMI from a configured instance
Suppose your web-1 from Chapter 7 or 9 is working perfectly. Let's make a reusable image of it.
Step 1 — Clean up (optional but good): remove temporary files and secrets you don't want copied, e.g. rm -f ~/.bash_history.
Step 2 — Create image: EC2 → Instances → select web-1 → Actions → Image and templates → Create image.
- Image name:
web-nginx-v1, description:Nginx + mysite, tested. - No reboot — leave unticked (recommended) — see the table below.
- Instance volumes: review sizes/types; add tags → Create image.
Step 3 — Wait: EC2 → Images → AMIs → status changes from pending to available (a few minutes). Under Snapshots you will see the snapshot(s) created for it.
| No-reboot option | Pros | Cons |
|---|---|---|
| Off (default — instance reboots) | Filesystem is flushed and consistent; safest image | Short downtime during reboot |
| On (no reboot) | Zero downtime | Data being written at that moment may be inconsistent (like pulling the power cable); databases may need recovery |
Launch a new instance from your AMI and verify
- EC2 → AMIs → select
web-nginx-v1→ Launch instance from AMI. - Choose instance type, the same key pair and the
web-sgsecurity group → Launch instance. - When it is running, open
http://<NEW_PUBLIC_IP>— your site should appear without installing anything.
# on the new instance
sudo service nginx status # or httpd / apache2
curl -I http://localhost
ls /var/www/mysite
Things that differ on the copy
The new instance gets a new instance ID, private IP and public IP. If your config hard-codes the old IP (for example Nginx server_name 13.x.x.x or WordPress site URL), update it — or move the Elastic IP to the new instance.
Copy an AMI to another region
AMIs are regional. To launch the same server in another region (for disaster recovery or users abroad): select the AMI → Actions → Copy AMI → destination region (e.g. ap-south-2 Hyderabad) → name → (optional) encryption → Copy AMI. Then switch the console to the destination region and wait for it to become available.
aws ec2 copy-image --source-region ap-south-1 --source-image-id ami-0123456789abcdef0 \
--region ap-south-2 --name "web-nginx-v1-hyd"
Share an AMI with another AWS account (brief)
Select the AMI → Actions → Edit AMI permissions → keep Private → Add account ID → enter the 12-digit account ID → Save changes. The other account finds it under AMIs → Private images. If the AMI's snapshots are encrypted with a customer managed KMS key, that key must also be shared; AMIs encrypted with the default aws/ebs key cannot be shared this way. Never make an AMI public if it contains your code, keys or passwords.
Deregister an AMI and delete its snapshots
Deregistering an AMI does not delete its snapshots — and snapshots keep costing money.
- EC2 → AMIs → select the AMI → Actions → Deregister AMI (newer consoles offer a Delete associated snapshots option — the UI may vary) → confirm.
- EC2 → Snapshots → find snapshots whose description says
Created by CreateImage(i-...) for ami-...→ Actions → Delete snapshot.
aws ec2 deregister-image --image-id ami-0123456789abcdef0
aws ec2 delete-snapshot --snapshot-id snap-0123456789abcdef0
The golden AMI idea
A golden AMI is a standard, pre-hardened, fully patched image with your common software (web server, agents, monitoring, security settings) already installed. Teams launch every new server from it instead of configuring each one by hand, so all servers are identical and launch fast. Rebuild the golden AMI regularly with the latest patches (tools like EC2 Image Builder automate this) and version it: golden-web-v1, v2, ...
Ravindra Bagale's Tip
Before any risky change — OS upgrade, PHP version change, big config edit — take an AMI (or at least a snapshot). If the change goes wrong, launch from the AMI and you are back in minutes. In my sessions I call it the "undo button" of the cloud. Name AMIs with a clear version label like web-v3-before-php-upgrade so you know exactly what's inside.
Ravindra Bagale's Tip – मराठी
कोणताही धोकादायक बदल करण्याआधी — OS upgrade, PHP version बदलणं, मोठं config edit — एक AMI घ्या (किंवा निदान snapshot तरी). बदल फसला तर AMI मधून launch करा आणि काही मिनिटांत तुम्ही परत पूर्वस्थितीत असता. माझ्या sessions मध्ये मी याला cloud चं "undo button" म्हणतो. AMI ला web-v3-before-php-upgrade सारखं स्पष्ट version label द्या, म्हणजे आत नेमकं काय आहे ते कळतं.
Ravindra Bagale's Tip – हिंदी
कोई भी जोखिम वाला बदलाव करने से पहले — OS upgrade, PHP version बदलना, बड़ा config edit — एक AMI ले लो (या कम से कम snapshot). बदलाव गड़बड़ हुआ तो AMI से launch करो और कुछ ही मिनटों में सब पहले जैसा. अपने sessions में मैं इसे cloud का "undo button" कहता हूँ. AMI का नाम web-v3-before-php-upgrade जैसे साफ़ version label के साथ रखो, ताकि पता रहे अंदर क्या है.