Amazon EC2
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.
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.
| Family | Optimised for | Examples | Typical use |
|---|---|---|---|
| General purpose | Balanced CPU and memory | t3, t4g, m7i, m7g | Web servers, small apps, learning |
| Compute optimised | Fast CPUs | c7i, c7g | Batch processing, game servers, video encoding |
| Memory optimised | Lots of RAM | r7i, r7g, x2 | In-memory caches, large databases |
| Storage optimised | Fast local disks | i4i, d3 | High-throughput databases, data warehouses |
| Accelerated computing | GPUs or ML chips | g5, p5, inf2, trn1 | Machine 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:
| Option | How it works | Best for |
|---|---|---|
| On-Demand | Pay per second (Linux) or hour while running; no commitment | Learning, short or unpredictable workloads |
| Savings Plans | Commit to a fixed spend per hour for 1 or 3 years in return for a large discount | Steady workloads; flexible across instance types |
| Reserved Instances | Commit to a specific instance configuration for 1 or 3 years | Steady workloads that will not change type |
| Spot Instances | Use spare capacity at a deep discount, but AWS can reclaim it with a two-minute warning | Fault-tolerant jobs: batch processing, CI builds, ML training with checkpoints |
| Dedicated Hosts | A whole physical server for you | Licensing or compliance requirements |
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.
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.
Tip: use the ← and → keys to move between pages.
