Volume 4 · Chapter 8 — Compute and Containers

EC2 Instances, AMIs, Placement, and Lifecycle in Depth

Goutham Mayaluri 5 min read AWSCloudEC2Containers

8.1 Introduction

The fundamentals chapter covered what an instance is; the exam expects far more EC2 detail - the instance families and naming, burstable credits, placement groups, tenancy, the instance metadata service, user data, AMIs and golden images, and launch templates. These mechanics decide performance, cost, resilience, and security, and they appear constantly on the exam.

8.2 Instance Families and Naming

EC2 instances come in families optimized for different resource profiles, and the exam expects you to match a workload to a family.General purpose(M, T) balance CPU/memory for typical apps and web servers.Compute optimized(C) for CPU-bound work (batch, gaming, HPC).Memory optimized(R, X, high-memory) for large in-memory datasets and databases.Storage optimized(I, D) for high sequential/random I/O and large local storage.Accelerated computing(P, G, Inf, Trn) for GPUs/ML/inference. The naming decodes as family + generation + additional-capabilities + size (e.g.m6g.largeis general purpose, 6th gen, Graviton (ARM), large). TheT family is burstable: it earns CPU credits when idle and spends them to burst above a baseline; if credits run out performance throttles (or, in unlimited mode, you pay for sustained bursting) - a tested gotcha for steady CPU-heavy workloads that shouldn’t use T instances.

flowchart TD
  Q{Workload bottleneck?} -->|Balanced| GP[General purpose - M, T]
  Q -->|CPU-bound| CO[Compute optimized - C]
  Q -->|Large memory / DB| MO[Memory optimized - R, X]
  Q -->|High I/O / local storage| SO[Storage optimized - I, D]
  Q -->|GPU / ML| AC[Accelerated - P, G, Inf, Trn]
  GP -.T = burstable: CPU credits, throttles when depleted.-> Note[ ]

8.3 Placement Groups and Tenancy

Placement groupscontrol how instances are physically placed. AClustergroup packs instances close together in one AZ for lowest latency and highest throughput (HPC) - but higher correlated failure risk. ASpreadgroup places instances on distinct hardware (max 7 per AZ) to minimize correlated failures - for small critical sets. APartitiongroup spreads instances across partitions on separate racks (for large distributed systems like HDFS/Cassandra) so a rack failure hits one partition.Tenancyoptions:Shared(default, multi-tenant hardware),Dedicated Instances(your instances on hardware not shared with other accounts), andDedicated Hosts(a whole physical server you control - for per-socket/core BYOL licensing and visibility into the hardware). Choosing placement and tenancy for performance, resilience, licensing, or compliance is architect-level detail.

8.4 Instance Metadata Service, User Data, and Hibernate

The**Instance Metadata Service (IMDS)**is a link-local endpoint (169.254.169.254) an instance queries for its own metadata and, crucially, for the temporary credentials of its attached role.IMDSv2is the hardened, session-token-based version that mitigates SSRF attacks and should be enforced (a security best practice and exam point).User datais a script that runs at first boot to bootstrap the instance (install software, configure) - the basis for launch-time automation.Hibernatesaves the in-memory (RAM) state to the EBS root volume so the instance resumes faster with state intact (for long-boot apps), distinct from stop (which clears RAM). Knowing IMDSv2, user-data bootstrapping, and hibernate versus stop are tested operational details.

8.5 AMIs and Golden Images

AnAmazon Machine Image (AMI)is the template an instance boots from - OS plus pre-installed software and configuration. AMIs are Regional (copy them cross-Region for multi-Region deployments), can be public/private/shared, and back onto EBS snapshots. Thegolden AMIpattern bakes a hardened, fully-configured image (patched OS, agents, security config) so instances launch fast and identically without lengthy user-data setup - improving boot time, consistency, and security posture.EC2 Image Builderautomates building, testing, and distributing golden AMIs (and container images) on a schedule. The exam favours golden AMIs (built by Image Builder) for fast, consistent, secure launches over doing all configuration at boot via user data.

8.6 Launch Templates and Capacity

Alaunch templatecaptures the instance configuration (AMI, type, key pair, security groups, user data, IAM profile) and is the modern, versioned way to launch instances and configure Auto Scaling groups (superseding the older launch configurations, which are not versioned and lack newer features). For guaranteed capacity,On-Demand Capacity Reservationsreserve capacity in a specific AZ (billed at On-Demand, no term) so a scaling event or DR failover can always get instances, and reservations can pair with Savings Plans for the discount. The exam prefers launch templates over launch configurations and expects you to know capacity reservations guarantee AZ capacity for critical scaling/DR.

8.7 Banking Production Scenario

A bank runs its memory-heavy core-banking service on R-family instances (never burstable T for steady load), its batch reconciliation on C-family, and an ML fraud model on accelerated instances. A latency-critical low-latency component uses a cluster placement group; a small critical control set uses a spread placement group for hardware isolation. A per-core-licensed application runs on Dedicated Hosts. All instances enforce IMDSv2, launch from a hardened golden AMI built by EC2 Image Builder (patched, agents installed), and are defined by versioned launch templates used by the Auto Scaling groups. On-Demand Capacity Reservations guarantee the DR Region can obtain instances during a failover. This precise instance, placement, image, and capacity design is core professional-level EC2 competence.

8.8 Chapter Revision Notes

  • Instance families: general (M/T), compute (C), memory (R/X), storage (I/D), accelerated (P/G/Inf/Trn); T is burstable (CPU credits, throttles when depleted).
  • Placement groups: cluster (low latency, one AZ), spread (distinct hardware, ≤7/AZ, critical small sets), partition (racks, large distributed systems); tenancy: shared, Dedicated Instances, Dedicated Hosts (BYOL/visibility).
  • IMDSv2 (enforce it) delivers role credentials/metadata; user data bootstraps at first boot; hibernate saves RAM to EBS vs stop clearing it.
  • AMIs are Regional templates (copy cross-Region); golden AMIs (via EC2 Image Builder) give fast, consistent, secure launches.
  • Launch templates (versioned) supersede launch configurations; On-Demand Capacity Reservations guarantee AZ capacity for scaling/DR.