AWS Compute Comparison
EC2 vs Lambda: When to Use Each AWS Compute Service
A first-principles guide to choosing between EC2 and Lambda — covering cost crossover, architectural trade-offs, and the scenarios where each service wins.
<div class="quick-answer"> **Quick Answer:** Lambda wins for spiky/event-driven workloads under the 15-minute limit with predictable traffic. EC2 wins for continuous workloads, long-running processes, or when you need OS access, GPU, or licensed software. </div> Choosing between EC2 and Lambda is not a question of which service is better. It is a question of which execution model fits your workload. Getting this wrong leads to either over-engineered serverless architectures that fight Lambda's constraints, or underutilized EC2 instances paying for idle capacity around the clock. This comparison is written for CTOs and cloud architects who need a clear, quantified answer — not a feature checklist. ## The Core Distinction: Execution Model The fundamental difference between EC2 and Lambda is not the service itself but the billing and execution model. **EC2** provisions capacity. You pay for the instance whether it is processing requests or sitting idle. You control the OS, runtime, memory, CPU, and storage. The instance persists until you terminate it. **Lambda** executes code. You pay only for the milliseconds your function runs. AWS manages the underlying infrastructure entirely. The execution environment is ephemeral — it may be reused across invocations or discarded after a single call. This distinction has cascading implications for cost, architecture, operations, and developer experience. ## Cost Comparison Lambda pricing has three components: request count ($0.20 per 1 million requests), duration ($0.0000166667 per GB-second), and optional provisioned concurrency. EC2 pricing depends on instance type, commitment level, and operating system. | Scenario | Lambda Cost / Month | EC2 Equivalent | EC2 Cost / Month | | -------------------------------- | ------------------- | ------------------------- | ---------------- | | 5M requests, 500ms avg, 512 MB | ~$21 | t3.micro (on-demand) | ~$8 | | 50M requests, 500ms avg, 512 MB | ~$210 | t3.small (on-demand) | ~$15 | | 500M requests, 500ms avg, 1 GB | ~$4,200 | t3.large (1-yr reserved) | ~$50 | | Continuous 24/7 processing, 4 GB | ~$14,400 | r6g.large (1-yr reserved) | ~$150 | The cost story is clear: Lambda wins decisively at low-to-moderate volumes where idle time would otherwise dominate EC2 costs. At high, continuous volumes, EC2 reserved instances are dramatically cheaper. The crossover point for most workloads falls around **1 million compute-seconds per month** — roughly 11.5 continuous days of single-CPU execution. If your Lambda functions aggregate to more than that, run the numbers against a reserved EC2 instance. One cost frequently overlooked: **operational overhead**. EC2 requires OS patching, AMI management, auto-scaling configuration, and capacity planning. Lambda eliminates all of that. For small engineering teams, the labor savings often justify Lambda even above the theoretical EC2 cost threshold. ## Hard Limits: Where Lambda Cannot Go Lambda has architectural constraints that make it unsuitable for certain workloads. These are not soft limits you can tune — they are hard ceilings. | Constraint | Lambda Limit | EC2 Equivalent | | -------------------------------------- | -------------------------------- | ------------------------------- | | Maximum execution duration | 15 minutes | No limit | | Maximum memory | 10 GB | Instances up to 24 TB (u-24tb1) | | Maximum vCPUs (proportional to memory) | ~6 vCPUs (at 10 GB) | Up to 448 vCPUs (u-24tb1) | | Ephemeral storage (/tmp) | 512 MB – 10 GB | Instance store up to tens of TB | | Persistent local filesystem | Not supported | Full OS filesystem | | Default concurrent executions | 1,000 per account | No concurrency ceiling | | Cold start latency | 100 ms – 3 s (runtime-dependent) | None (persistent process) | **When EC2 is the only viable option:** - **Batch jobs exceeding 15 minutes** — video transcoding, large ETL pipelines, scientific simulations. Step Functions can chain Lambdas for some of these, but the overhead and complexity often make EC2 or Fargate simpler. - **High-memory workloads** — in-memory databases, large ML inference batches, JVM applications requiring 16+ GB heap. - **Licensed software** — Oracle Database, SQL Server, and other per-host licensed software cannot run on Lambda. - **GPU workloads** — ML training, video encoding, and graphics rendering require EC2 GPU instances (P-series, G-series, Inf2). - **Stateful long-running services** — message queue consumers, WebSocket servers, and services maintaining in-memory state between requests. ## Architectural Patterns by Use Case ### APIs and Web Services Lambda is the default choice for new REST and GraphQL APIs via API Gateway or ALB. Cold start latency is manageable with provisioned concurrency for latency-sensitive paths. Lambda scales automatically to tens of thousands of concurrent requests without pre-provisioning. Use EC2 (or ECS/Fargate) when the API has persistent connection requirements (WebSockets, gRPC streaming), requires session-level state, or has latency SLAs under 50 ms that cannot tolerate cold starts even with provisioned concurrency. ### Batch Processing Lambda handles short-to-medium batch jobs well: file processing triggered by S3 events, SQS queue consumers, and scheduled aggregation jobs under 15 minutes. For long-running batch, AWS Batch on EC2 or Fargate is purpose-built and significantly cheaper at scale than Lambda. ### Event-Driven Pipelines Lambda is purpose-built for event-driven architectures. Native integrations with S3, SQS, SNS, DynamoDB Streams, Kinesis, and EventBridge mean you can wire up complex data pipelines with minimal code. EC2 can consume these same events but requires you to run and manage the polling process yourself. ### Machine Learning Inference Lambda supports inference for small, fast models (scikit-learn, lightweight ONNX, AWS Lambda layers with ML runtimes). For larger models (LLMs, large PyTorch models), EC2 with GPU or AWS Inferentia instances is required. SageMaker Inference endpoints are also worth considering — they abstract instance management while supporting model sizes Lambda cannot handle. ## Decision Framework Use this checklist to make the call: | Question | Lambda | EC2 | | --------------------------------------------------------------------- | ------------------------------------------------------- | --------------------------------------------- | | Does the workload run continuously 24/7? | No — Lambda is event-driven | Yes — EC2 is designed for persistent capacity | | Does execution exceed Lambda's 15-minute limit? | No | Yes — use EC2 for long-running processes | | Does it need more than 10 GB of memory? | No | Yes — EC2 supports up to TB-scale memory | | Is traffic unpredictable or spiky? | Yes — Lambda auto-scales; pay only for executions | Maybe — sustained traffic favors reserved EC2 | | Is the workload event-driven? | Yes — APIs, webhooks, queues, S3 triggers | No — continuous processing prefers EC2 | | Does it require OS-level access or custom software? | No — Lambda is sandboxed | Yes — EC2 gives full OS control | | Is it licensed software (Oracle, SQL Server)? | No | Yes — per-host licensing requires EC2 | | Does it need GPU (ML training, video encoding)? | No | Yes — EC2 supports NVIDIA, AWS Trainium | | Is cold start latency a hard requirement? | Maybe — use provisioned concurrency to warm instances | Yes — instances are always warm | | Is cost efficiency at low traffic (< 1M requests/month) the priority? | Yes — Lambda eliminates idle costs | No — EC2 still costs $8–15/month minimum | | Is cost efficiency at high sustained throughput the priority? | No — Lambda becomes expensive above 500M requests/month | Yes — reserved instances cost 70% less | ## Related Comparisons Explore other technical comparisons: - [AWS Lambda vs ECS Fargate](/compare/aws-lambda-vs-ecs-fargate) - [AWS ECS vs EKS](/compare/aws-ecs-vs-eks) ## Why Work With FactualMinds FactualMinds is an **AWS Select Tier Consulting Partner** — a verified AWS designation earned through demonstrated technical expertise and customer success. Our architects have run production workloads for companies from seed-stage startups to enterprises. - **AWS Select Tier Partner** — verified by AWS Partner Network - **Architecture-first approach** — we evaluate your specific workload before recommending a solution - **No lock-in consulting** — we document everything so your team can operate independently - [AWS Marketplace Seller](https://aws.amazon.com/marketplace/seller-profile?id=seller-m753gfqftla7y) ---
Quick Answer: Lambda wins for spiky/event-driven workloads under the 15-minute limit with predictable traffic. EC2 wins for continuous workloads, long-running processes, or when you need OS access, GPU, or licensed software.
Choosing between EC2 and Lambda is not a question of which service is better. It is a question of which execution model fits your workload. Getting this wrong leads to either over-engineered serverless architectures that fight Lambda’s constraints, or underutilized EC2 instances paying for idle capacity around the clock.
This comparison is written for CTOs and cloud architects who need a clear, quantified answer — not a feature checklist.
The Core Distinction: Execution Model
The fundamental difference between EC2 and Lambda is not the service itself but the billing and execution model.
EC2 provisions capacity. You pay for the instance whether it is processing requests or sitting idle. You control the OS, runtime, memory, CPU, and storage. The instance persists until you terminate it.
Lambda executes code. You pay only for the milliseconds your function runs. AWS manages the underlying infrastructure entirely. The execution environment is ephemeral — it may be reused across invocations or discarded after a single call.
This distinction has cascading implications for cost, architecture, operations, and developer experience.
Cost Comparison
Lambda pricing has three components: request count ($0.20 per 1 million requests), duration ($0.0000166667 per GB-second), and optional provisioned concurrency. EC2 pricing depends on instance type, commitment level, and operating system.
| Scenario | Lambda Cost / Month | EC2 Equivalent | EC2 Cost / Month |
|---|---|---|---|
| 5M requests, 500ms avg, 512 MB | ~$21 | t3.micro (on-demand) | ~$8 |
| 50M requests, 500ms avg, 512 MB | ~$210 | t3.small (on-demand) | ~$15 |
| 500M requests, 500ms avg, 1 GB | ~$4,200 | t3.large (1-yr reserved) | ~$50 |
| Continuous 24/7 processing, 4 GB | ~$14,400 | r6g.large (1-yr reserved) | ~$150 |
The cost story is clear: Lambda wins decisively at low-to-moderate volumes where idle time would otherwise dominate EC2 costs. At high, continuous volumes, EC2 reserved instances are dramatically cheaper.
The crossover point for most workloads falls around 1 million compute-seconds per month — roughly 11.5 continuous days of single-CPU execution. If your Lambda functions aggregate to more than that, run the numbers against a reserved EC2 instance.
One cost frequently overlooked: operational overhead. EC2 requires OS patching, AMI management, auto-scaling configuration, and capacity planning. Lambda eliminates all of that. For small engineering teams, the labor savings often justify Lambda even above the theoretical EC2 cost threshold.
Hard Limits: Where Lambda Cannot Go
Lambda has architectural constraints that make it unsuitable for certain workloads. These are not soft limits you can tune — they are hard ceilings.
| Constraint | Lambda Limit | EC2 Equivalent |
|---|---|---|
| Maximum execution duration | 15 minutes | No limit |
| Maximum memory | 10 GB | Instances up to 24 TB (u-24tb1) |
| Maximum vCPUs (proportional to memory) | ~6 vCPUs (at 10 GB) | Up to 448 vCPUs (u-24tb1) |
| Ephemeral storage (/tmp) | 512 MB – 10 GB | Instance store up to tens of TB |
| Persistent local filesystem | Not supported | Full OS filesystem |
| Default concurrent executions | 1,000 per account | No concurrency ceiling |
| Cold start latency | 100 ms – 3 s (runtime-dependent) | None (persistent process) |
When EC2 is the only viable option:
- Batch jobs exceeding 15 minutes — video transcoding, large ETL pipelines, scientific simulations. Step Functions can chain Lambdas for some of these, but the overhead and complexity often make EC2 or Fargate simpler.
- High-memory workloads — in-memory databases, large ML inference batches, JVM applications requiring 16+ GB heap.
- Licensed software — Oracle Database, SQL Server, and other per-host licensed software cannot run on Lambda.
- GPU workloads — ML training, video encoding, and graphics rendering require EC2 GPU instances (P-series, G-series, Inf2).
- Stateful long-running services — message queue consumers, WebSocket servers, and services maintaining in-memory state between requests.
Architectural Patterns by Use Case
APIs and Web Services
Lambda is the default choice for new REST and GraphQL APIs via API Gateway or ALB. Cold start latency is manageable with provisioned concurrency for latency-sensitive paths. Lambda scales automatically to tens of thousands of concurrent requests without pre-provisioning.
Use EC2 (or ECS/Fargate) when the API has persistent connection requirements (WebSockets, gRPC streaming), requires session-level state, or has latency SLAs under 50 ms that cannot tolerate cold starts even with provisioned concurrency.
Batch Processing
Lambda handles short-to-medium batch jobs well: file processing triggered by S3 events, SQS queue consumers, and scheduled aggregation jobs under 15 minutes. For long-running batch, AWS Batch on EC2 or Fargate is purpose-built and significantly cheaper at scale than Lambda.
Event-Driven Pipelines
Lambda is purpose-built for event-driven architectures. Native integrations with S3, SQS, SNS, DynamoDB Streams, Kinesis, and EventBridge mean you can wire up complex data pipelines with minimal code. EC2 can consume these same events but requires you to run and manage the polling process yourself.
Machine Learning Inference
Lambda supports inference for small, fast models (scikit-learn, lightweight ONNX, AWS Lambda layers with ML runtimes). For larger models (LLMs, large PyTorch models), EC2 with GPU or AWS Inferentia instances is required. SageMaker Inference endpoints are also worth considering — they abstract instance management while supporting model sizes Lambda cannot handle.
Decision Framework
Use this checklist to make the call:
| Question | Lambda | EC2 |
|---|---|---|
| Does the workload run continuously 24/7? | No — Lambda is event-driven | Yes — EC2 is designed for persistent capacity |
| Does execution exceed Lambda’s 15-minute limit? | No | Yes — use EC2 for long-running processes |
| Does it need more than 10 GB of memory? | No | Yes — EC2 supports up to TB-scale memory |
| Is traffic unpredictable or spiky? | Yes — Lambda auto-scales; pay only for executions | Maybe — sustained traffic favors reserved EC2 |
| Is the workload event-driven? | Yes — APIs, webhooks, queues, S3 triggers | No — continuous processing prefers EC2 |
| Does it require OS-level access or custom software? | No — Lambda is sandboxed | Yes — EC2 gives full OS control |
| Is it licensed software (Oracle, SQL Server)? | No | Yes — per-host licensing requires EC2 |
| Does it need GPU (ML training, video encoding)? | No | Yes — EC2 supports NVIDIA, AWS Trainium |
| Is cold start latency a hard requirement? | Maybe — use provisioned concurrency to warm instances | Yes — instances are always warm |
| Is cost efficiency at low traffic (< 1M requests/month) the priority? | Yes — Lambda eliminates idle costs | No — EC2 still costs $8–15/month minimum |
| Is cost efficiency at high sustained throughput the priority? | No — Lambda becomes expensive above 500M requests/month | Yes — reserved instances cost 70% less |
Related Comparisons
Explore other technical comparisons:
Why Work With FactualMinds
FactualMinds is an AWS Select Tier Consulting Partner — a verified AWS designation earned through demonstrated technical expertise and customer success. Our architects have run production workloads for companies from seed-stage startups to enterprises.
- AWS Select Tier Partner — verified by AWS Partner Network
- Architecture-first approach — we evaluate your specific workload before recommending a solution
- No lock-in consulting — we document everything so your team can operate independently
- AWS Marketplace Seller
Frequently Asked Questions
Is Lambda cheaper than EC2?
When should I use EC2 instead of Lambda?
What are Lambda's limitations vs EC2?
Can Lambda replace EC2?
How do I migrate from EC2 to Lambda?
Not Sure Which AWS Service Is Right?
Our AWS-certified architects help engineering teams choose the right architecture for their workload, scale, and budget — before they build the wrong thing.
