Amazon Machine Image (AMI)
An Amazon Machine Image (AMI) is a master template used to create EC2 instances.
It defines the software/OS stack that will run on the instance, including:
- Root volume snapshot (OS, boot loader, applications, libraries, data).
- Block device mapping (how EBS volumes attach at launch).
- Launch permissions (which AWS accounts can use the AMI).
In other words, an AMI is the “blueprint” for your virtual servers.
Types of AMIs
- AWS Marketplace AMIs
- Pre‑configured images provided by vendors (e.g., Windows Server, commercial Linux distros, software bundles).
- Usually comes with licensing costs.
- AWS provided/Community AMIs
- Public base images (Amazon Linux, Ubuntu, Debian, Windows).
- Some from community — caution needed regarding security.
- Custom (User‑created) AMIs
- Capture your pre‑configured instance after installing updates/software.
- Allows standardized deployments.
- Golden AMI (Best Practice)
- An organization’s approved, hardened, security‑patched AMI for consistent, compliant deployments.
AMI Lifecycle
- Create AMI from an existing EC2 instance (Create Image).
- Store AMI — metadata + snapshots in Amazon S3 (managed by AWS).
- Launch from AMI — EC2 creates volumes from underlying snapshots and bootstraps instance.
- Update AMI — apply patches to an instance, re‑create AMI for next deployments.
- Deregister AMI if no longer needed (snapshots persist until deleted).
AMI Storage
- EBS‑backed AMI
- Root volume stored as an EBS snapshot.
- Instance can stop/start (data persists).
- You can resize root volume.
- Instance Store‑backed AMI(Legacy)
- Root volume stored on ephemeral storage (local disks).
- Faster boot, but data lost on stop/terminate.
- Less commonly used now.
AMI Permissions & Sharing
- By default, AMIs are private to your AWS account.
- Permissions you can set:
- Private: Only your account can use.
- Explicit sharing: Specific AWS account IDs.
- Public: Anyone can launch an EC2 from it (⚠ caution: usually not recommended).
- Encrypted AMIs:
- If AMI includes encrypted EBS snapshots, you must also share the KMS key with recipient accounts.
Multi‑Region and Multi‑Account AMIs
- Copy AMI across regions to deploy globally.
- Snapshots get replicated under the hood.
- For cross‑account deployments:
- Copy AMI with
--copy-image. - Share snapshots + KMS permissions if encrypted.
- Copy AMI with
AMI Creation Methods
Console:
EC2 > Instances > Actions > Create Image.
Automation:
- Use EC2 Image Builder (standardizes AMI pipelines).
- Or use packer (HashiCorp tool) for consistent AMI builds.
AMIs and Snapshots Relationship
- Creating an AMI → AWS takes snapshots of the volumes attached to the instance.
- When you launch an instance from an AMI → new volumes are created from those snapshots.
Thus:
- Snapshot = backup of a single volume.
- AMI = blueprint that references one or more snapshots.
AMI and User Data
- AMI defines base configuration.
- User Data scripts (at launch) enable instance customization (installing Apache, adding index.html, etc).
- Combination ensures repeatable + flexible deployments.
Encryption in AMIs
- If volumes in the AMI are encrypted:
- Any derived snapshot/volume remains encrypted.
- Sharing requires KMS policy updates.
- If default EBS encryption is enabled, launching an unencrypted AMI still produces encrypted volumes in your account.
Use Cases
- Standardized deployment: Launch 100 identical app servers from a single AMI.
- Disaster recovery: Maintain golden AMIs for rapid failover.
- Blue/Green deployments: Bake a golden AMI for each release.
- Scaling: Launch from AMI in Auto Scaling Groups with consistent configuration.
Create Image (AMI) vs Create Launch Template
Topic | Create Image (AMI) | Create Launch Template |
|---|---|---|
What it is | A snapshot of a server’s disk (OS + software + settings) | A recipe for how to start a server (launch settings) |
Think of it as | “What’s on the disk” | “How to launch it” |
Main purpose | Standardize the machine baseline | Standardize launch parameters and make launches repeatable |
Defines | OS, patches, installed software, configs, block device mapping | AMI ID, instance type/size, VPC/subnet, security groups, key pair, IAM role, user data, tags, purchasing options |
How they work together | You pick/build an AMI, then reference it inside a Launch Template | Uses an AMI and adds all runtime settings; used by ASG/Spot/Fleets |
Change frequency | Infrequent (rebuild when OS or core software changes) | More frequent (new versions for parameter tweaks/rollouts) |
Versioning | No native versioning (create a new AMI each time) | Built‑in versioning with easy rollback to previous versions |
Customization at launch | Minimal; add last‑mile config via user data | High; user data, networking, capacity type, tags, etc. |
Reuse | Copy/share across regions and accounts (with permissions) | Reused within services (ASG, Spot, EMR) in the same account |
Sharing and permissions | Can be private, shared to accounts, or public; encrypted AMIs require sharing KMS key too | Stays in account; users need permissions and access to the referenced AMI |
Encryption | AMI can include encrypted EBS snapshots (KMS) | Can enforce encrypted EBS at launch and specify KMS key |
Cost | Pay for snapshot storage backing the AMI | No direct cost; affects instance/storage costs chosen |
Best for | Golden images; fast, consistent boot with pre‑installed stack | Consistent, safe, repeatable launches; Auto Scaling and Spot |
Quick memory | AMI = the base “image” | Launch Template = the launch “recipe” |
