Amazon EC2
What is it?
Amazon EC2 provides resizable virtual servers in the cloud that you can launch in minutes and pay for by the time you use them.
Explain like I'm 5
Why was it created?
Buying physical servers is slow and inflexible. EC2 was created so you can spin up virtual machines on demand and scale them as needs change.
Where is it used?
- Hosting web and app servers
- Running backend workloads
- Batch and compute jobs
- Lift-and-shift of existing apps
Why should developers care?
EC2 is one of AWS's foundational services and a common building block in cloud architectures and interviews.
How does it work?
You choose an instance type (CPU, memory, etc.) and a machine image, then launch one or more virtual servers. You can scale the number of instances up or down and pay for what you run.
Real-world example
A web app runs on several EC2 instances behind a load balancer; during a sale, more instances launch automatically and shut down afterward.
Common use cases
- General-purpose servers
- Scaling web tiers
- Compute-heavy jobs
- Migrating existing applications
Advantages
- Launch servers in minutes
- Many instance sizes
- Pay for what you use
- Full control over the operating system
Disadvantages
- You manage the OS and patching
- Easy to leave instances running and overpay
- More work than serverless options
When should you use it?
When you need full control of a server or to run software that expects a traditional machine.
When should you avoid it?
For event-driven workloads where serverless (Lambda) avoids managing servers entirely.
Alternatives
Related terms
Interview questions
Beginner
- What is an EC2 instance?
- How is EC2 billed?
Intermediate
- What is an instance type?
- How does auto-scaling work with EC2?
Senior
- When would you choose EC2 over Lambda or containers?
- How do you optimize EC2 cost with reserved or spot capacity?
Common misconceptions
- "EC2 manages everything for you" — you're still responsible for the operating system, patching, and scaling configuration.
- "EC2 is always the cheapest compute" — serverless or spot options can cost less for the right workloads.
Fun facts
- EC2 stands for Elastic Compute Cloud.
- Spot instances let you use spare capacity at a steep discount, with the trade-off that they can be reclaimed.
Timeline
- 2006 — EC2 launches as one of AWS's first services
Learning resources
Quick summary
Amazon EC2 offers on-demand virtual servers you can launch, size, and scale in the cloud, paying only for what you run.
Cheat sheet
- Resizable virtual servers
- Pay per use
- You manage the OS
- Scale instances up and down