What is Amazon EC2 and when would you use it?
Learn what Amazon EC2 is, how instances and AMIs work, pricing models, and when to use EC2 for scalable cloud compute workloads.
Expected Interview Answer
Amazon EC2 (Elastic Compute Cloud) is a service that provides resizable virtual servers, called instances, in the AWS cloud, letting you run applications without owning physical hardware.
You choose an instance type (CPU, memory, storage, and network profile), launch it from an Amazon Machine Image (AMI), and pay only for the capacity you use. EC2 gives you full OS-level control, so you use it when you need a general-purpose server for web apps, batch jobs, or legacy software that a managed service cannot host. It integrates with Auto Scaling, Elastic Load Balancing, and security groups to scale and secure workloads.
- Launch and terminate servers in minutes
- Pay-as-you-go with no upfront hardware cost
- Full control over the operating system
- Scales up or out on demand with Auto Scaling
- Wide choice of instance types for any workload
AI Mentor Explanation
Renting an EC2 instance is like a team booking a practice net at a stadium for exactly the hours they need. They pick the pitch type that suits their session, use it fully during the booking, then release it so another team can train — paying only for the slots they reserved, never for building their own ground.
Step-by-Step Explanation
Step 1
Choose an AMI
Pick an Amazon Machine Image that defines the OS and pre-installed software for your instance.
Step 2
Select an instance type
Match CPU, memory, and network capacity to your workload, e.g. t3.micro for testing or c6i for compute-heavy jobs.
Step 3
Configure networking and security
Place the instance in a VPC subnet and attach a security group that controls inbound and outbound traffic.
Step 4
Add storage and key pair
Attach EBS volumes for persistent disk and assign an SSH key pair for secure login.
Step 5
Launch and connect
Start the instance, then connect via SSH or Session Manager to deploy and run your application.
What Interviewer Expects
- Understanding that EC2 provides virtual servers, not managed apps
- Awareness of instance types and AMIs
- Knowledge of pay-as-you-go pricing models
- How EC2 relates to security groups and VPC
- When to choose EC2 over serverless or managed compute
Common Mistakes
- Calling EC2 a serverless service
- Confusing an instance type with an AMI
- Forgetting that stopped instances still incur EBS storage charges
- Assuming AWS patches the guest OS for you
Best Answer (HR Friendly)
“Amazon EC2 lets a company rent virtual computers in the cloud instead of buying physical servers. You turn them on when you need computing power, pay only for what you use, and switch them off when you are done, which saves money and scales easily.”
Code Example
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-0123456789abcdef0 \
--subnet-id subnet-0123456789abcdef0 \
--count 1Follow-up Questions
- How does EC2 Auto Scaling decide when to add or remove instances?
- What is the difference between On-Demand, Reserved, and Spot instances?
- How do security groups differ from network ACLs?
- When would you choose AWS Lambda over EC2?
MCQ Practice
1. What does an Amazon Machine Image (AMI) provide when launching an EC2 instance?
An AMI is a template containing the operating system, application server, and applications used to boot an instance.
2. Which pricing model offers the largest discount for interruptible, fault-tolerant workloads?
Spot instances use spare capacity at steep discounts but can be reclaimed by AWS with short notice.
Flash Cards
What does EC2 stand for? — Elastic Compute Cloud — resizable virtual servers in AWS.
What defines an instance's OS and software? — The Amazon Machine Image (AMI).
What controls inbound and outbound traffic to an instance? — A security group acting as a virtual firewall.
Do stopped instances incur charges? — Compute stops, but attached EBS storage still incurs cost.