EC2Amazon Elastic Compute Cloud
Virtual machines you choose, size and run yourself: the most flexible compute on AWS, and the most work.
Where EC2 takes you7 steps, all open
- I know the problem it solves
- I can picture it
- I know how it scales
- I know how it fails
- I know when to choose it
- I can use it in a design
- I can answer an exam question
What & why
A whole machine, when nothing less will doEC2 gives you virtual machines, called instances. You choose the image it boots, an AMI; the instance type, which sets its CPU, memory, storage and network; the subnet it runs in; and where it keeps its data. After that, patching, sizing and scaling are yours.
It is the most flexible compute on AWS, and the most work. Reach for something more managed when you can, and for EC2 when you need what only a whole machine gives you.
Reach for it when
- you need full control of the operating system
- the software needs privileged access, such as a kernel driver of its own
- a job runs longer than Lambda's 15-minute limit
- licences are per socket or per core: Dedicated Hosts
It is the wrong tool when
- short code runs in response to events: that is Lambda
- you want to run containers without managing servers: that is Fargate
- nobody wants to patch an operating system, and nothing needs one
Mental model
Renting a carYou pick a model and what comes with it, and pay by the second while you have it. Commit to a year or three and it costs less. Take a car from the spare pool and it is cheap, but the company can take it back with two minutes' warning. Anything left in the glovebox is gone when the car goes back; your luggage in a locker stays.
AMIInstance typeOn-DemandSavings PlansSpotInstance storeHow it works
From an image to a running instance- Choose an AMIThe operating system and software it boots. An AMI belongs to one Region, and can be copied to others.
- Choose a typeThe instance type sets the hardware: general purpose, compute, memory or storage optimised, or accelerated.
- Launch itInto a subnet, with security groups and an IAM role. It gets a private IPv4 address, and a public one if you ask.
- Keep the dataOn a persistent volume, or in S3 or EFS. Instance store is scratch space that is erased when the instance stops.
- Billing
- Per second60 s minimum; SUSE Linux by the hour
- Spot interruption
- 2 minwarning, in metadata and EventBridge
- Spread placement
- ≤ 7running instances per AZ
- Partition placement
- ≤ 7partitions per AZ
- Instance store
- Lost on stopkept through a reboot
- IMDSv2 token
- ≤ 6 hsession-oriented
Public IPv4 address
- assigned from Amazon's pool, not yours
- released when the instance stops, hibernates or terminates
- a new one is assigned when it starts again
Elastic IP address
- static, and yours until you release it
- can be remapped to another instance to mask a failure
- charged whether it is in use or idle, like every public IPv4 address
Architecture
Two zones behind a load balancerThe load balancer sends requests only to healthy targets. With the default settings it checks each instance every 30 seconds and takes it out of service after two failures in a row, so an instance that dies stops getting traffic within about a minute.
Scaling
Up, or outUp: change an instance's type for a bigger one. Out: add more instances behind a load balancer. Out is what survives a failure, and it is what Auto Scaling automates.
The numbers in this simulation are made up to show the shape, not the capacity of any real instance type.
Capacity: 500 requests a second for each.
200 requests a second more than 2 instances can take. Add 1 more, or shed the load.
Failure simulation
Lose an instance, then lose a zoneBoth instances in AZ a
CustomersServed by Web 1 and Web 2
AZ a
AZ b
Click a node to make it fail. The timings in the log are the real ones, played 10× faster.
- Everything is up. Take a node or a whole zone down.
One instance in each zone
CustomersServed by Web 1 and Web 2
AZ a
AZ b
Click a node to make it fail. The timings in the log are the real ones, played 10× faster.
- Everything is up. Take a node or a whole zone down.
An instance lives in one Availability Zone. Put both in the same zone and losing it is an outage; spread them and it is lost capacity.
Its instance store is erased when the instance stops, so nothing you cannot lose belongs there. An Elastic IP address can be remapped to a replacement to mask a failure.
If every target fails its health checks at once, an Application Load Balancer sends traffic to all of them anyway, rather than to none.
Security
Credentials, metadata and the way inA role, never keys. An instance gets temporary credentials from its IAM role, through an instance profile, and they are updated automatically. An instance has one role at a time.
Require IMDSv2. The instance metadata service is where those credentials come from. IMDSv2 makes every request start with a session token, which AWS recommends as defence in depth against open firewalls, reverse proxies and SSRF.
Security groups let in only what a rule allows: a new security group allows no inbound traffic at all.
No public address just to log in. EC2 Instance Connect Endpoint connects you to an instance from the internet without the instance having a public IPv4 address.
Cost
How you are charged, not what it costs todayBy the second. Linux, Windows, RHEL and Ubuntu Pro instances are billed per second with a 60-second minimum; SUSE Linux Enterprise Server by the full hour.
Commit for less. Savings Plans commit to a consistent amount of spend per hour for 1 or 3 years, across instance types. Reserved Instances commit to one instance configuration for 1 or 3 years.
Spot uses spare capacity for much less, and can be interrupted with a two-minute warning.
Also on the bill: every public IPv4 address. Instance store is included in the instance's price.
Prices change, so none are printed here. Check the EC2 pricing pages on aws.amazon.com.
Comparison
Six ways to pay for the same instance| Option | You commit to | Can be interrupted | Choose it when |
|---|---|---|---|
| On-Demand | Nothing; pay by the second | No | Usage is short, spiky or unknown |
| Savings Plans | Spend per hour, for 1 or 3 years | No | Usage is steady, but types and sizes change |
| Reserved Instances | One configuration, for 1 or 3 years | No | The same instance runs all the time |
| Spot Instances | Nothing | Yes, with a 2-minute warning | Work that can stop and restart |
| Dedicated Hosts | A physical server of your own | No | Per-socket or per-core licences, or compliance |
| Capacity Reservations | Capacity in one Availability Zone | No | You must be able to launch at a given moment |
SAA traps
The phrase in the question, and what it meansfault-tolerant batch jobs, at the lowest costSpot Instances
The work can restart, so a two-minute interruption notice is acceptable.
steady usage, but the instance families keep changingA Savings Plan
It commits to spend per hour, not to one configuration.
software licensed per socket or per coreDedicated Hosts
A physical server of your own, so existing licences apply.
the lowest latency between the nodes of an HPC jobA cluster placement group
Close together in one Availability Zone, with the highest throughput between them.
a few critical instances must never share hardwareA spread placement group
Each on distinct hardware, up to seven running instances per zone.
HDFS or Cassandra nodes across separate racksA partition placement group
Partitions do not share racks, and the application can see which is where.
the data on the instance store was gone after a stopInstance store is temporary
It survives a reboot, not a stop. Keep data on a persistent volume or in S3.
the public IP changed after the instance was restartedAn Elastic IP address
A public IPv4 address is released on stop; an Elastic IP address stays yours.
Scenario
Exam style, marked when you answerA company runs a nightly analytics job on EC2 that takes about four hours. It saves checkpoints, so if it is interrupted it can resume where it stopped. The finance team wants it to cost as little as possible. Which purchasing option should a solutions architect choose?
Practice
Fill the gap, the way the challenges workA vendor's image analysis software installs its own kernel driver, and each job runs for up to six hours. Jobs arrive on a queue, and results are written to S3. What runs the software?
Quick revision
The night before the exam- Billing
- Per second,
60 sminimum; SUSE Linux by the hour. - Spot
- Spare capacity for much less, with a two-minute warning.
- Savings Plans or RIs
- Commit to spend per hour, or to one configuration, for 1 or 3 years.
- Placement groups
- Cluster: one AZ, low latency. Partition: separate racks. Spread: up to 7 per AZ.
- Instance store
- Survives a reboot, not a stop.
- Public IP
- Changes on stop and start; an Elastic IP address does not.
- Credentials
- A role through an instance profile, with IMDSv2 required.
Next: Auto ScalingKeeps the right number of EC2 instances running. It replaces the ones that fail, and adds or removes instances as the load changes.
Open Auto ScalingChecked against
Every fact on this page was checked against AWS’s own documentation on 15 Sept 2026. If AWS has changed something since, its page is the one to trust.
- Amazon EC2 instance types
- Amazon Machine Images in Amazon EC2
- Amazon EC2 billing and purchasing options
- Spot Instance interruption notices
- Placement strategies for your placement groups
- Instance store temporary block storage
- Data persistence for instance store volumes
- Use the Instance Metadata Service
- Amazon EC2 On-Demand pricing
- Elastic IP addresses
- Amazon EC2 instance IP addressing
- Health checks for Application Load Balancer target groups
- Use an IAM role to grant permissions to applications on EC2
- Lambda quotas
- Fargate security considerations for Amazon ECS