Amazon EC2
Virtual servers
Rent virtual servers (instances) on AWS, choose your own CPU, RAM and operating system, and install whatever you want.
- Cost$$ Medium
- Difficulty●●●●●
- Costs money when idle?Yes
- Self-managed
- In examsCLF · SAA · DVA · SOA
Think of it asLike renting an empty apartment: pick the size you want, then arrange and clean the inside yourself.
Where does EC2 fit?
A real example, step by step
- An online shop needs to run a PHP web app and a reporting tool that only runs on Windows.
- You pick a t3.medium (2 vCPUs, 4 GB RAM), choose an operating system and click Launch; about a minute later the machine is running.
- You SSH in, install the web server and configure it like any normal server; the EBS disk keeps your data even across reboots.
- The machine runs 24/7, so it is billed every second, even at midnight with no customers. A one-year commitment with Savings Plans cuts the cost considerably.
- As traffic grows, you put the instances in an Auto Scaling group behind a load balancer so machines are added automatically at peak times.
When to use it
✓ Use it when
You need full control of the operating system, run traditional software, or run continuously.
✗ Avoid it when
You only need to run short code triggered by events → Lambda; you only need to run containers → Fargate.
Common uses
- Traditional web/app servers, moved as-is from on-prem (lift-and-shift)
- Apps that need a specific operating system, drivers or GPUs (ML, rendering)
- Self-installed databases when you need deep customization
- Build/CI machines, game servers running continuously
EC2, Lambda or Fargate?
| What you manage | Everything: OS, patching, scaling | Only the function code | The container image and task settings |
|---|---|---|---|
| Run time | No limit | Up to 15 minutes per invocation | No limit |
| Billing | Time the instance is on, even when idle | Requests and run time | vCPU and memory while tasks run |
| Best for | Traditional software that needs full control | Event processing, small APIs | Containerized web services |
What does it cost?
- Pricing model: Billed per second (Linux) by instance type. Save up to ~72% with Savings Plans/Reserved Instances, up to ~90% with Spot (can be reclaimed).
- Free tier: Accounts created before July 15, 2025: 750 hours of t2/t3.micro per month for 12 months. New accounts: deducted from Free Tier credits.
Forgetting to stop instances; public IPv4 costs ~$0.005/hour per IP; EBS volumes and snapshots are still billed after the instance stops; data transfer out to the Internet.
“Reduce cost for steady, always-on workloads” → Savings Plans or Reserved Instances; “work that can restart and tolerate interruption” → Spot. An app on EC2 that calls other AWS services → attach an IAM role, never store access keys on the instance.
Try real exam questions
1A company has released a new version of its production application. The company's workload uses Amazon EC2, AWS Lambda, AWS Fargate, and Amazon SageMaker. The company wants to cost optimize the workload now that usage is at a steady state. The company wants to cover the most services with the fewest savings plans. Which combination of savings plans will meet these requirements? (Choose two.)
- APurchase an EC2 Instance Savings Plan for Amazon EC2 and SageMaker.
- BPurchase a Compute Savings Plan for Amazon EC2, Lambda, and SageMaker.
- CPurchase a SageMaker Savings Plan.
- DPurchase a Compute Savings Plan for Lambda, Fargate, and Amazon EC2.
- EPurchase an EC2 Instance Savings Plan for Amazon EC2 and Fargate.
Show answer
Correct answer: C, D
A Compute Savings Plan covers EC2, Lambda and Fargate together. SageMaker isn't covered by Compute Savings Plans, so it needs its own SageMaker Savings Plan. An EC2 Instance Savings Plan applies only to EC2 in one instance family and region.
2What is the time period with which metric data is sent to CloudWatch when detailed monitoring is enabled on an Amazon EC2 instance?
- A15 minutes.
- B5 minutes.
- C1 minute.
- D45 seconds.
Show answer
Correct answer: C
With detailed monitoring, EC2 sends metrics to CloudWatch every 1 minute; the default (basic monitoring) is every 5 minutes.
Frequently asked questions
Do I still pay for an EC2 instance after I stop it?
You stop paying for instance hours, but attached EBS volumes, snapshots and any Elastic IPs you keep are still billed. To stop all charges, terminate the instance and delete the volumes, snapshots and IPs you no longer need.
How do On-Demand, Reserved Instances, Savings Plans and Spot differ?
On-Demand is billed per second with no commitment. Reserved Instances and Savings Plans give deep discounts in exchange for a 1- or 3-year commitment. Spot uses spare AWS capacity and is the cheapest, but can be reclaimed with a two-minute warning, so it suits work that can be restarted, such as batch processing.
What do AWS exams ask about EC2?
Choosing a purchase option (On-Demand, Reserved, Savings Plans, Spot) for a scenario, picking an instance family (compute-, memory- or storage-optimized), placement groups, using IAM roles instead of access keys on the instance, and telling EBS apart from instance store (which loses data when the instance stops).