AWS Lambda runs your code when something happens and bills only for the time it runs. Amazon EC2 gives you a virtual server that runs until you stop it. Both can power an API, a job runner or a website backend, but they suit very different traffic patterns, budgets and teams.
This guide compares the two on cost, limits, performance and day-to-day operations, then shows which workloads fit each and how to combine them.
The core difference
With EC2 you rent capacity: an instance with a fixed amount of CPU and memory, running whatever you install. You manage the operating system, scaling and patching, and you pay for every second it runs, busy or idle.
With Lambda you upload a function and connect it to a trigger such as an API Gateway request, an S3 upload, a queue message or a schedule. AWS runs as many copies as needed and you pay per request and per millisecond of run time. The Lambda developer guide lists supported runtimes and triggers.

Side-by-side comparison
| Factor | Lambda | EC2 |
|---|---|---|
| Billing | Per request and per ms of duration | Per second while running |
| Idle cost | None | Full instance price |
| Max run time | 15 minutes per invocation | Unlimited |
| Memory | 128 MB to 10,240 MB | From under 1 GiB to many TiB |
| GPUs | No | Yes |
| Scaling | Automatic, per request | Auto Scaling groups you configure |
| Server management | None | OS, patches and agents |
How the costs compare
Lambda’s always-free tier includes 1 million requests and 400,000 GB-seconds of compute per month, and the Lambda pricing page lists the rates beyond that. A webhook handler or an internal API with a few thousand calls a day can cost almost nothing.
The picture flips with steady load. A function busy around the clock pays for every millisecond, while one small EC2 instance, especially with a Savings Plan, can handle the same traffic for a fixed price. Model both with real request counts, durations and memory before deciding. The EC2 pricing models guide explains the discounts on the server side.
Lambda limits to know
- Maximum duration of 15 minutes per invocation.
- Memory between 128 MB and 10,240 MB; CPU scales with memory.
- Ephemeral /tmp storage configurable up to 10 GB.
- Request and response payload limits for synchronous calls, so large files go through S3.
- Concurrent executions limited per Region.
The full list is in the Lambda quotas documentation.
Performance and cold starts
An EC2 instance is always warm. Lambda creates execution environments on demand, and the first request to a new environment pays a cold start while the runtime and code load. For most APIs this is a small, occasional delay. For latency-sensitive endpoints, keep packages small, choose lighter runtimes, use SnapStart where supported, or pay for provisioned concurrency.
For heavy computation, EC2 offers specialised families, local NVMe storage and GPUs that Lambda does not. The instance type guide and the GPU instances guide cover those options.
Operations and security
Lambda removes OS patching, capacity planning and most scaling work. You still own the code, its dependencies, IAM permissions and monitoring. Give each function its own execution role with least privilege; the IAM roles and policies guide shows how.
EC2 gives full control and full responsibility: patching, hardening, backups and access. The shared responsibility guide explains where AWS’s work ends in each case.
Which workloads fit each
Lambda fits
- REST and GraphQL APIs with variable traffic.
- Webhooks, form handlers and chat bots.
- Image resizing or file processing triggered by S3 uploads.
- Scheduled tasks and queue consumers.
- Glue between AWS services.
EC2 fits
- WordPress, game servers and traditional web stacks.
- Steady high-traffic services and long-running workers.
- Databases you manage yourself.
- Machine learning, rendering and GPU workloads.
- Software that needs a specific OS, kernel module or licence.
Using them together
Most real systems mix both. A typical design runs the main application on EC2 in an Auto Scaling group, and uses Lambda for image processing, scheduled clean-ups, alerts and integrations. The Auto Scaling and load balancer guide covers the EC2 side.
Quotas on new accounts
Both services have Regional limits. Lambda concurrency and EC2 vCPU quotas on new accounts can start below the published defaults, which can throttle a launch. Check Service Quotas in your Region, request increases early, and review the quota details listed with each AWS account for sale if you need headroom from the start.
Lambda vs EC2 questions
Is Lambda cheaper than EC2?
For low or spiky traffic, usually yes, because you pay nothing while code is idle and the always-free tier covers 1 million requests and 400,000 GB-seconds a month. For steady, high traffic, an EC2 instance with a Savings Plan is often cheaper.
What is the maximum run time for a Lambda function?
A single Lambda invocation can run for up to 15 minutes. Longer jobs need Step Functions to split the work, or a service such as EC2, ECS or AWS Batch.
Can Lambda run a WordPress site?
Not practically. WordPress expects a persistent PHP server and file system. Use Lightsail or EC2 for WordPress, and Lambda for smaller APIs and background tasks.
What is a Lambda cold start?
When Lambda creates a new execution environment it must load your code and runtime first, which adds latency to that request. Smaller packages, lighter runtimes, SnapStart for supported runtimes and provisioned concurrency reduce the effect.
Does Lambda have account limits?
Yes. Concurrent executions are limited per Region, and new accounts can start below the standard default. Check the quota in Service Quotas and request an increase before a launch.
Editorial guide by Mark Biden · Reviewed 24 November 2026. Official sources are linked beside the relevant sections; AWS features, quotas and prices change, so confirm details in the AWS console before relying on them.

Leave a Reply