Skip to content
Kuza Ndoto Academy

Amazon EC2

Beginner → IntermediateChapter 3 · Page 9 of 304 min readUpdated 15 Nov 2026

Amazon Elastic Compute Cloud (EC2) rents you virtual servers, called instances, that you can start in minutes and pay for by the second. You choose the operating system, the size of the machine and where it runs, and you get full control of it, much like a computer in your own server room, without buying any hardware.

The parts of an instance

When you launch an instance you make a few key choices:

  • AMI (Amazon Machine Image): a template containing the operating system and any preinstalled software, for example Amazon Linux 2023, Ubuntu Server or Windows Server. You can also build your own AMI from a configured server.
  • Instance type: how much CPU, memory and network capacity the virtual machine has.
  • Storage: usually an EBS volume as the root disk. EBS is network-attached storage that survives stopping and starting the instance (see EBS & EFS).
  • Security group: a virtual firewall listing which inbound traffic is allowed, such as HTTPS from anyone and SSH only from your IP.
  • Key pair: the public half is placed on the server; you keep the private half to log in with SSH.
  • Network: the VPC and subnet (and therefore the Availability Zone) the instance runs in.
  • IAM role (optional): gives programs on the instance temporary AWS credentials through an instance profile.
Security group EC2 instance t3.micro: 2 vCPU, 1 GiB Amazon Linux 2023 AMI OS + software template EBS volume root disk gp3, 8 GiB Key pair (SSH) IAM role (instance profile) The instance runs in one subnet of a VPC, in one Availability Zone
Figure 1. An instance is launched from an AMI, stores data on an attached EBS volume and sits behind a security group. The key pair lets you log in; the IAM role lets its software call AWS without stored keys.

Instance types

Instance type names follow a pattern. In m7g.large, m is the family, 7 the generation, g an attribute (here, an AWS Graviton ARM processor) and large the size. Each size step up (large, xlarge, 2xlarge...) roughly doubles CPU and memory, and the price.

FamilyOptimised forExamplesTypical use
General purposeBalanced CPU and memoryt3, t4g, m7i, m7gWeb servers, small apps, learning
Compute optimisedFast CPUsc7i, c7gBatch processing, game servers, video encoding
Memory optimisedLots of RAMr7i, r7g, x2In-memory caches, large databases
Storage optimisedFast local disksi4i, d3High-throughput databases, data warehouses
Accelerated computingGPUs or ML chipsg5, p5, inf2, trn1Machine learning training and inference, graphics

The t family is "burstable": instances earn CPU credits while idle and spend them during short bursts. They are cheap for websites with uneven traffic but slow down, or cost extra in unlimited mode, under constant heavy load. Graviton (g) instances usually give better price-performance if your software runs on ARM, which most Linux software does.

Pricing models

EC2 offers several ways to pay for the same machine. Check the EC2 pricing page for actual rates in your Region; the principles are:

OptionHow it worksBest for
On-DemandPay per second (Linux) or hour while running; no commitmentLearning, short or unpredictable workloads
Savings PlansCommit to a fixed spend per hour for 1 or 3 years in return for a large discountSteady workloads; flexible across instance types
Reserved InstancesCommit to a specific instance configuration for 1 or 3 yearsSteady workloads that will not change type
Spot InstancesUse spare capacity at a deep discount, but AWS can reclaim it with a two-minute warningFault-tolerant jobs: batch processing, CI builds, ML training with checkpoints
Dedicated HostsA whole physical server for youLicensing or compliance requirements
Example

A Nairobi e-commerce shop runs two web servers all year, plus extra servers during the festive-season sales, plus a nightly job that resizes product photos. A sensible mix: a Savings Plan covering the two always-on servers, On-Demand for the festive-season extras, and Spot for the photo job, which can simply retry if interrupted.

Instance lifecycle and billing

An instance moves through states: pending → running → stopping → stopped, and finally terminated when you delete it.

  • Running: you pay for compute time.
  • Stopped: no compute charge, but you still pay for its EBS volumes and any Elastic IP address.
  • Terminated: the instance is gone; by default its root volume is deleted too.
Warning

The classic surprise bill: an instance launched for a tutorial and forgotten for a month, often in a Region you rarely check. Also note that AWS charges for public IPv4 addresses, and a stopped instance's volumes keep costing money. When you finish practising, terminate instances you no longer need and release unused Elastic IPs.

Key points

  • EC2 gives you virtual servers with full control over the operating system.
  • An instance combines an AMI, an instance type, EBS storage, a security group, a key pair and a network location.
  • Instance type names encode family, generation, attributes and size.
  • On-Demand is flexible, Savings Plans and Reserved Instances reward commitment, and Spot is cheapest but interruptible.
  • Stopped instances still incur storage charges; terminate what you do not need.
Up next · ComputeLaunching Your First EC2 InstanceKey pairs, security groups and connecting to a server.
→

Tip: use the ← and → keys to move between pages.