Skip to main content
Skip to main content
Still in beta — questions, comments or suggestions? aramb@aramb.dev

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).

15 min
Introductory
AWS Free TierFREE TIER

All services used in this lesson are covered by the AWS Free Tier.

AWS Services Used

Amazon EC2750 hours per month of t2.micro or t3.micro for 12 monthsAWS Lambda1 million free requests per month (Always Free)

Learning outcomes

By the end of this lesson, you will be able to:

  1. Explain what Amazon EC2 is and what it does.
  2. Describe what you manage when you use EC2.
  3. Explain the difference between EC2 and Lambda in plain terms.
  4. Choose EC2 or Lambda for a simple scenario.
  5. 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

FeatureAmazon EC2AWS Lambda
ModelVirtual server you manageCode execution (Serverless)
OS ControlFull control (Root/Admin access)No direct OS management
ScalingManual or via Auto ScalingAutomatic (highly scalable)
Execution TimeRuns until you stop itMax 15 minutes per task
PricingPay by the hour/second while runningPay 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

Micro-Activity

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?

Micro-Activity

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.


Knowledge Check

Knowledge Check
1 / 5

What is an Amazon EC2 instance?