Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSCompute

Amazon EC2

Elastic Compute Cloud — virtual servers in the cloud covering instance types, AMIs, placement groups, Nitro, tenancy, and pricing models.

Overview

Amazon Elastic Compute Cloud (EC2) is AWS's core compute service — resizable virtual servers (instances) in the cloud that provide on-demand capacity for virtually any workload.

EC2 underpins the majority of AWS architectures. An instance is a virtual machine running on a physical host in an Availability Zone (AZ). Each instance is launched from an Amazon Machine Image (AMI), attached to a Virtual Private Cloud (VPC) subnet, and assigned an instance type that determines its compute, memory, storage, and networking resources.


Core Concepts

ConceptDescription
InstanceA virtual server running on AWS infrastructure; defined by an instance type and launched from an AMI
AMIAmazon Machine Image — a template containing the OS, application server, and applications
Instance TypeDetermines the hardware profile: vCPUs, memory, storage, and network bandwidth
Security GroupStateful virtual firewall controlling inbound and outbound traffic at the instance level
Key PairRSA or ED25519 key pair used for SSH (Linux) or RDP password decryption (Windows)
Elastic IPStatic public IPv4 address that can be remapped between instances
User DataBootstrap script (bash/PowerShell) executed on first launch — runs as root/Administrator
Instance MetadataInstance-accessible endpoint (169.254.169.254) exposing identity, network, and IAM role info
Nitro SystemAWS's custom hypervisor and hardware platform — enables bare metal, enhanced networking, and EBS optimisation

Instance Families

Instance type naming follows the pattern: <family><generation>.<size> (e.g., m7i.xlarge).

FamilyCategoryOptimised ForExample Types
MGeneral PurposeBalanced compute, memory, networkingm7i, m7g, m6a
CCompute OptimisedCPU-intensive: batch processing, ML inference, gamingc7i, c7g, c6a
RMemory OptimisedIn-memory databases, real-time analyticsr7i, r7g, r6a
XMemory OptimisedVery large in-memory workloads (SAP HANA, etc.)x2idn, x2iedn
IStorage OptimisedHigh sequential I/O, data warehousing, Hadoopi4i, i3, i3en
DStorage OptimisedDense HDD storage, distributed file systemsd3, d3en
PAccelerated (GPU)ML training, HPC, computational fluid dynamicsp5, p4d
GAccelerated (GPU)Graphics rendering, video encoding, ML inferenceg6, g5
InfAccelerated (Inferentia)ML inference at low costinf2
TBurstableBaseline + burst CPU credits; dev/test, small appst3, t3a, t4g
HpcHPC OptimisedTightly-coupled HPC, weather modellinghpc7g, hpc7a

Suffix modifiers: g = Graviton (ARM), a = AMD, n = enhanced networking, d = local NVMe SSD, e = extra memory or storage.

SAA/SAP Tip: Graviton instances (suffix g) deliver up to 40% better price-performance than x86 equivalents for most workloads. Prefer them unless the application requires x86 binaries.


Amazon Machine Images (AMIs)

An AMI packages everything needed to launch an instance: root volume snapshot, launch permissions, and block device mapping.

AMI SourceDescription
AWS-providedAmazon Linux, Ubuntu, Windows Server — maintained by AWS
MarketplaceThird-party vendor AMIs (some with license fees baked in)
CommunityShared publicly by other AWS users — use with caution
CustomCreated from an existing instance or imported from on-premises

Key behaviours:

  • AMIs are region-scoped — copy an AMI to target region before launching there
  • AMIs can be shared cross-account or made public
  • Golden AMI pattern: pre-bake software + config into an AMI to reduce bootstrap time

Placement Groups

Placement groups control how instances are physically positioned on underlying hardware.

StrategyBehaviourUse CaseLimitation
ClusterAll instances in a single AZ, close together on same rackLow-latency, high-throughput HPC / tightly coupledNo multi-AZ; higher blast radius
SpreadEach instance on distinct hardware (max 7 per AZ per group)Individual critical instances needing HAMax 7 instances per AZ
PartitionInstances spread across logical partitions on separate racksLarge distributed workloads (HDFS, Cassandra, Kafka)Max 7 partitions per AZ

Exam Trap: Spread placement groups support a maximum of 7 running instances per AZ. For large-scale distributed workloads, use Partition placement groups instead.


Tenancy

Tenancy ModelDescriptionCost Impact
Shared (default)Instance runs on shared hardware alongside other AWS customersLowest
Dedicated InstanceInstance runs on hardware dedicated to one AWS account; other instances from the same account may share itHigher
Dedicated HostAn entire physical server allocated to one account — visibility into sockets, cores, and host affinityHighest

SAA/SAP Tip: Dedicated Hosts are required for Bring Your Own License (BYOL) models that bind to physical hardware (e.g., Windows Server, SQL Server per-socket licensing). Dedicated Instances do not provide host-level visibility.


Networking

FeatureDescription
Elastic Network Interface (ENI)Virtual network card; an instance can have multiple ENIs in different subnets
Enhanced Networking (ENA)Up to 200 Gbps using SR-IOV; enabled by default on Nitro instances
Elastic Fabric Adapter (EFA)OS-bypass networking for HPC and ML training — lower latency than ENA
Elastic IP (EIP)Static public IPv4; charged when not associated with a running instance
Public IPAuto-assigned from AWS pool; released on stop; cannot be remapped

Storage Options

Storage TypePersistenceUse Case
EBS volumesPersist beyond stopBoot volume, databases, general-purpose block storage
Instance StoreEphemeral (lost on stop/terminate)Temp data, caches, scratch space, buffers
EFS / FSxNetwork-attachedShared file storage across multiple instances

Exam Trap: Instance store volumes are ephemeral — all data is lost when the instance stops, terminates, or the underlying hardware fails. Never store critical data on instance store alone.


Purchasing Options

ModelCommitmentDiscount vs On-DemandBest For
On-DemandNone0%Short-term, unpredictable workloads
Reserved Instances1 or 3 yrUp to 72%Steady-state workloads with predictable usage
Savings Plans1 or 3 yrUp to 72%Flexible commitment across instance families
Spot InstancesNoneUp to 90%Fault-tolerant, flexible-start workloads
Dedicated HostsNone or 1/3 yrVariesBYOL, compliance requiring host-level control
Capacity ReservationsNone0% (On-Demand price)Guaranteed capacity in a specific AZ

Spot Instances

Spot Instances use spare EC2 capacity at steep discounts (up to 90% off On-Demand). AWS can reclaim them with a 2-minute warning.

  • Spot Fleet — request a mix of instance types and AZs to meet target capacity
  • Spot Block (deprecated for new launches) — reserved Spot for 1–6 hours
  • Best for: batch jobs, CI/CD builds, data analysis, containerised workloads

SAA/SAP Tip: Combine Spot with On-Demand in an Auto Scaling group using a mixed instances policy to balance cost and availability. Set the On-Demand base to handle minimum steady-state load.

Reserved Instances vs Savings Plans

AspectReserved Instances (RI)Compute Savings Plans
ScopeSpecific instance type + region (or AZ)Any instance type, region, OS, or tenancy
FlexibilityConvertible RIs allow family changesAutomatically applies to cheapest usage
Payment optionsAll Upfront / Partial / No UpfrontAll Upfront / Partial / No Upfront
Applies toEC2 onlyEC2, Fargate, Lambda

Instance Lifecycle

pending → running ↔ stopping → stopped → terminated
                  ↘ shutting-down → terminated
  • Stop: EBS root volume persists; instance store data is lost. No compute charges while stopped (EBS charges continue).
  • Hibernate: RAM contents are saved to EBS root volume. On start, RAM is restored — faster than a cold boot. Root volume must be encrypted and large enough.
  • Terminate: Instance is deleted. EBS root volume is deleted by default (configurable via DeleteOnTermination).

SAA/SAP Tip: EC2 Hibernate is useful for long-initialisation applications (large in-memory caches, JVM warm-up). The instance must use an encrypted EBS root volume and belongs to specific instance families with RAM ≤ 150 GB.


Common Use Cases

  • Web application hosting — Run HTTP servers (Apache, Nginx, Node.js) behind an Application Load Balancer with Auto Scaling.
  • Batch processing — Process large datasets using Spot Instances for cost efficiency with fault-tolerant job queues.
  • Development and testing — Spin up and tear down environments on demand; T-family burstable instances keep costs low.
  • High-Performance Computing — Cluster placement groups + EFA + P/Hpc instances for tightly-coupled parallel workloads.
  • Database hosting — Run self-managed databases (when RDS lacks the required engine) on memory-optimised instances with EBS io2.
  • Machine learning training — GPU instances (P5, G6) with large datasets on S3 or FSx for Lustre.

SAA/SAP Exam Tips

SAA/SAP Tip: When a question mentions "per-socket" or "per-core" licensing, the answer is Dedicated Hosts — not Dedicated Instances. Only Dedicated Hosts provide visibility into physical hardware.

Exam Trap: Stopping and starting an EC2 instance may move it to different underlying hardware — the public IP changes (unless using an Elastic IP) and instance store data is lost.

SAA/SAP Tip: For "lowest cost" questions with fault-tolerant workloads, Spot Instances are almost always the answer. For steady-state, choose Reserved Instances or Savings Plans.

Exam Trap: EC2 User Data runs only on the first boot by default. To run scripts on every start, configure cloud-init accordingly or use a systemd service.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAmazon EC2Baseline
AzureAzure Virtual MachinesSimilar instance families; different naming
GCPGoogle Compute EnginePredefined + custom machine types
On-PremisesVMware vSphere, KVM, Hyper-VTraditional hypervisor-based virtualisation

Pricing Model

DimensionUnitNotes
ComputePer-secondMinimum 60 seconds; Linux and Windows per-second billing
EBS storageGB-monthSeparate from EC2; varies by volume type
Data transfer outGBFirst 100 GB/month free; intra-AZ traffic is free for same account
Elastic IPPer-hour idleCharged when not associated with a running instance
AMI storageGB-month (S3)EBS snapshots backing the AMI incur standard snapshot costs

Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page