CalcTune
🎮
Fun · Developer

AWS Lambda vs EC2 Cost Calculator

Compare the monthly cost of running your workload on AWS Lambda (serverless) versus an EC2 instance (server). Enter your Lambda invocation volume, execution parameters, and EC2 instance details to see which option saves money — and at what request volume they break even.

Lambda (Serverless)

EC2 (Server)

$
Example values — enter yours above
CHEAPER OPTION
Lambda Wins$57.65 vs EC2
LAMBDA MONTHLY COST
$3.08
EC2 MONTHLY COST
$60.74
Lambda Cost Breakdown
Requests Charge
$1.0000
Compute Charge
$2.0833
Break-even Point
98,490,678 requests/month

Below this volume, Lambda is cheaper. Above it, EC2 is cheaper.

Lambda pricing: $0.20/1M requests + $0.0000166667/GB-second. EC2 cost is hourly rate × hours. Prices are approximate and may not reflect the latest AWS rates.

AWS Lambda vs EC2: A Complete Cost Comparison Guide

One of the most consequential architecture decisions in cloud computing is choosing between serverless functions and traditional virtual machines. AWS Lambda and Amazon EC2 represent two fundamentally different pricing models: Lambda charges based on the actual compute consumed per invocation, while EC2 charges a flat hourly rate for the instance regardless of how busy it is. This distinction means neither option is universally cheaper — the optimal choice depends on your workload's request volume, execution characteristics, and traffic patterns.

How AWS Lambda Pricing Works

Lambda pricing has two components. The first is a per-request charge of $0.20 per 1 million requests ($0.0000002 per invocation). The second is a compute charge based on the amount of memory allocated and the duration of execution, measured in GB-seconds. The rate is $0.0000166667 per GB-second. For example, a function with 512 MB of memory running for 100 milliseconds consumes 0.512 GB × 0.1 seconds = 0.0512 GB-seconds per invocation.

Memory is billed in 64 MB increments with a minimum of 128 MB. Duration is billed in 1 ms increments. Lambda also provides a generous free tier: 1 million free requests and 400,000 GB-seconds of compute per month, which can cover low-traffic workloads at no cost.

An important optimization lever is memory allocation. Since Lambda allocates CPU proportional to memory, increasing memory often speeds up execution enough to reduce total GB-seconds (and thus cost) even at a higher memory tier.

How EC2 Pricing Works

EC2 charges a fixed hourly rate based on the instance type and region, regardless of actual CPU utilization or request volume. An instance running at 1% utilization costs the same as one running at 100%. For an always-on instance, this typically works out to 730 hours per month.

EC2 pricing spans a wide range. The smallest instances cost under $0.005/hour, while high-performance instances can cost tens of dollars per hour. A typical general-purpose web server might use a t3.medium at approximately $0.0416/hour, costing about $30/month always-on.

EC2 pricing can be significantly reduced with Reserved Instances (up to 72% savings with a 1-year commitment) or Spot Instances (up to 90% savings for fault-tolerant workloads). This calculator uses on-demand pricing as the baseline; if your team uses Reserved Instances, enter the effective hourly rate after the reservation discount.

Understanding the Break-Even Point

The break-even point is the monthly request volume at which Lambda and EC2 costs are equal. Below this volume, Lambda is cheaper because you only pay for what you use. Above it, EC2 becomes cheaper because the fixed monthly cost is spread over more requests.

The break-even formula is: EC2 Monthly Cost divided by Lambda Cost Per Request. The per-request Lambda cost combines the $0.0000002 request charge with the memory-duration compute charge. For a 128 MB function running 100 ms per invocation, the per-request cost is approximately $0.00000041. A t3.medium at $30/month breaks even at roughly 73 million requests per month for that Lambda configuration.

Longer or more memory-intensive functions have a lower break-even, making EC2 attractive at smaller volumes.

Traffic Pattern Considerations

The raw cost comparison understates Lambda's advantage for spiky traffic. If your application receives 10 million requests on the first day of the month and near zero for the rest, Lambda naturally scales to zero and charges only for that burst. An EC2 instance running the whole month still costs the full monthly rate.

Conversely, for steady high-volume workloads, EC2 is typically more cost-effective. A well-tuned EC2 instance handling 10,000 requests per second around the clock is processing far more requests than most Lambda break-even points.

Auto Scaling EC2 fleets complicate the comparison — you can scale EC2 capacity up and down based on demand, paying only for the instances you run. This hybrid approach captures some of Lambda's variable-cost advantages while retaining EC2's per-request economics at scale.

Beyond Cost: Other Decision Factors

Cost is one dimension of the Lambda vs. EC2 decision, but operational concerns matter too. Lambda eliminates server management, OS patching, capacity planning, and most infrastructure overhead. This operational simplicity has real value that does not appear in a cost calculator. For small teams or early-stage products, the reduced operational burden often justifies Lambda even if the raw compute cost is higher.

Lambda does impose constraints: a 15-minute maximum execution timeout, memory limits up to 10 GB, and cold start latency that can add 100–1000 ms to the first invocation after an idle period. For long-running tasks or latency-sensitive applications requiring consistent sub-100 ms response times, EC2 may be architecturally necessary.

EC2 gives full control over the environment: OS configuration, network settings, instance storage, GPU access, and the ability to run any software. For workloads requiring specific kernel modules, low-level networking, or GPU compute, EC2 is often the only viable option regardless of cost.

Practical Cost Optimization Tips

If Lambda is your choice, tuning memory allocation is the most impactful optimization. AWS Lambda Power Tuning (an open-source tool) automates testing your function at different memory levels to find the optimal cost-performance balance. Many functions achieve the lowest cost-per-invocation at memory levels above the minimum 128 MB.

For EC2, right-sizing is the most important optimization. AWS Cost Explorer and Compute Optimizer provide recommendations for instance type changes that could reduce costs without impacting performance. Graviton-based instances (arm64) typically offer 20% better cost-performance than x86 equivalents for compatible workloads.

Frequently Asked Questions

How is AWS Lambda compute cost calculated?

Lambda compute cost is based on GB-seconds: the amount of memory allocated (in GB) multiplied by the execution duration (in seconds), multiplied by $0.0000166667 per GB-second. For example, a 256 MB function running for 500 ms consumes 0.256 GB × 0.5 s = 0.128 GB-seconds, costing approximately $0.00000213 per invocation. Add the per-request charge of $0.0000002 for the total.

At what point does EC2 become cheaper than Lambda?

This depends on your Lambda configuration and EC2 instance size. As a rough guide, for a 128 MB Lambda function running 100 ms per invocation, EC2 (at $30/month) becomes cheaper above roughly 70–80 million requests/month. Functions with higher memory or longer duration reach the break-even point at lower request volumes.

Does Lambda have a free tier?

Yes. AWS Lambda's permanent free tier includes 1 million free requests per month and 400,000 GB-seconds of compute per month. For a 128 MB function, this translates to approximately 3.2 billion milliseconds of execution time. This free tier applies to all Lambda invocations in your account, not just new accounts.

Should I use on-demand, reserved, or spot pricing for EC2?

On-demand pricing (the default in this calculator) offers maximum flexibility. Reserved Instances (1 or 3 year terms) can reduce costs by up to 72%, suitable for stable baseline workloads. Spot Instances offer up to 90% savings but can be interrupted with 2 minutes notice, suitable only for fault-tolerant workloads. If you use Reserved Instances, enter the effective hourly rate after the discount.

What about Lambda cold starts?

Lambda cold starts occur when a new execution environment is initialized, typically adding 100–1000 ms latency. Cold starts are more frequent for low-traffic functions. Lambda Provisioned Concurrency eliminates cold starts but adds a flat hourly cost. This calculator does not include Provisioned Concurrency costs — add those separately if applicable.