What Amazon EC2 Is, When to Use It, and How It Differs from Lambda
Understand the core compute options in AWS: virtual servers (EC2) and serverless functions (Lambda).
All services used in this lesson are covered by the AWS Free Tier.
AWS Services Used
Learning outcomes
By the end of this lesson, you will be able to:
- Explain what Amazon EC2 is and what it does.
- Describe what you manage when you use EC2.
- Explain the difference between EC2 and Lambda in plain terms.
- Choose EC2 or Lambda for a simple scenario.
- Recognize the main parts involved in launching an EC2 instance: AMI, instance type, key pair, VPC, security group, and EBS volume.
What EC2 is
EC2 is the “virtual server you manage” compute option in AWS. Lambda is the “run code without managing servers” compute option.
A simple memory rule:
- EC2 = more control, more responsibility — you manage a persistent virtual server
- Lambda = less server management, more event-driven simplicity — your code runs on demand with no server to keep alive
1) What Amazon EC2 is
Amazon EC2 stands for Amazon Elastic Compute Cloud. AWS defines an EC2 instance as a virtual server in the AWS cloud environment. You have full control over the instance from the moment you launch it until you terminate it.
That means EC2 feels closer to the traditional “I have a server” model:
- You choose the OS (Linux, Windows, etc.)
- You install your own software
- You configure updates and security patches
- You decide how the machine should behave
2) The first-launch building blocks
When you launch an EC2 instance, you aren't just saying "run my code." You are making choices about the virtual hardware and software environment. AWS frames the first-launch experience around these core pieces:
A) AMI (Amazon Machine Image)
The template for your server. It includes the operating system and any pre-installed software.
B) Instance type
The "size" of your server. It determines the CPU, memory (RAM), storage, and network performance.
C) Key pair
The credentials used to prove your identity when connecting to your instance securely.
D) VPC and Subnet
The virtual network where your instance lives. AWS provides a Default VPC in every Region so you can get started quickly.
E) Security group
A virtual firewall that controls which traffic is allowed to reach your instance (inbound) and which traffic can leave it (outbound).
F) EBS volume
Persistent storage (like a virtual hard drive) attached to your instance. The root volume contains the operating system.
3) How EC2 differs from Lambda
While EC2 gives you a whole virtual machine, AWS Lambda runs your code without you needing to think about servers at all.
Comparison at a glance
| Feature | Amazon EC2 | AWS Lambda |
|---|---|---|
| Model | Virtual server you manage | Code execution (Serverless) |
| OS Control | Full control (Root/Admin access) | No direct OS management |
| Scaling | Manual or via Auto Scaling | Automatic (highly scalable) |
| Execution Time | Runs until you stop it | Max 15 minutes per task |
| Pricing | Pay by the hour/second while running | Pay per request and duration |
Note
The 15-Minute Rule: Lambda has a maximum timeout of 900 seconds (15 minutes). If your task takes longer than that, you almost certainly need EC2 or a container-based service.
4) When to choose which?
Choose EC2 when:
- You want a traditional server experience.
- You need OS-level control or custom OS packages.
- You have a long-running service that stays up 24/7.
- You want to "lift and shift" an existing app that runs on a physical server.
Choose Lambda when:
- The work is event-driven (e.g., "do this when a file is uploaded").
- You want to focus on code, not infrastructure.
- The task is short-lived (seconds or a few minutes).
- Traffic is unpredictable and you want automatic scaling.
Micro-activity 1: Match the EC2 Building Blocks
EC2 Launch Components
Match each EC2 term to its role in the launching process.
Examples
Choose one, then match it on the right
Characteristics
Select an example first
0 of 5 matched so far.
Micro-activity 2: EC2 or Lambda?
Compute Scenarios
Based on the requirements, which compute service is the better fit?
Examples
Choose one, then match it on the right
Characteristics
Select an example first
0 of 5 matched so far.
Summary
Amazon EC2 is your "virtual server in the cloud." It gives you the most control but requires the most management. You choose the AMI, instance type, and networking.
AWS Lambda is "serverless compute." You provide the code, and AWS handles the rest. It's perfect for short, event-driven tasks, but it has a 15-minute time limit.