Lambda feels cheap at first. A function that runs a million times a month at low memory can cost less than a coffee. Then the product grows, traffic spikes, logs pile up, and the serverless bill starts to look like a real line item.
That is when Lambda cost optimization becomes a real job. The pricing is simple on paper, with a charge per request and a charge per GB-second, but the bill responds to many small choices: memory size, architecture, cold starts, event sources, retries, and the services wired around each function.
This guide explains those choices in plain language, using AWS’s own pricing pages and documentation. You will learn:
- How AWS Lambda pricing works, including the free tier and recent billing changes
- How to estimate and monitor Lambda spending
- The tactics that matter most, from memory tuning to event filtering
- When provisioned concurrency, Savings Plans, or Managed Instances make sense
- A step by step plan, common mistakes, and worked examples
Prices and features change, so confirm current rates for your Region on AWS’s pricing page before you budget.

What Is Lambda Cost Optimization?
Lambda cost optimization is the practice of reducing what you pay for AWS Lambda without hurting performance or reliability. It involves tuning memory and duration, choosing the right architecture and concurrency settings, avoiding unnecessary invocations, and watching related charges such as logs and API calls, using real usage data to guide each change.
The goal is not the lowest possible bill. It is the lowest bill that still meets your latency, reliability, and delivery goals. A function that costs a little more but saves a customer a two second wait can be the right choice.
How AWS Lambda Pricing Works
AWS describes Lambda pricing on its Lambda pricing page. For standard functions, you pay for requests and for duration. Everything else is an add-on.
The core formula is:
- Request cost = number of requests × $0.20 per million
- Duration cost = memory in GB × run time in seconds × number of invocations × the price per GB-second
In the first pricing tier, AWS lists $0.0000166667 per GB-second for x86 and $0.0000133334 for Arm. Duration is billed in 1 millisecond increments, and the price depends on the memory you configure, not the memory your code actually uses.
The Free Tier
Every account gets 1 million free requests and 400,000 GB-seconds of compute each month. It applies to both x86 and Graviton2 functions in aggregate, and it does not expire after 12 months. AWS’s free tier also includes 100 GiB of HTTP response streaming a month, and the first 6 MB of each streamed response is free.
The free tier matters most for small projects. Past a few million requests, it is a rounding error.
An AWS Example
AWS’s own example is a function with 1,536 MB of memory that runs 3 million times a month at 120 ms each:
- Compute: 3 million × 0.12 seconds = 360,000 seconds. At 1.5 GB, that is 540,000 GB-seconds.
- After the 400,000 free GB-seconds, 140,000 GB-seconds are billable, which costs $2.33.
- Requests: 3 million less 1 million free is 2 million billable, which costs $0.40.
- Total: $2.73 a month.
Memory Sets Both Price and Speed
Memory is the main control on a Lambda function. AWS allocates CPU in proportion to memory, anywhere from 128 MB to 10,240 MB in 1 MB steps. At 1,769 MB, a function has the equivalent of one vCPU.
That link is why memory tuning can lower cost. If more memory makes the function run much faster, the extra price per second can be paid back by a shorter run. We will test that idea in a later section.
Arm Costs Less Than x86
Functions on Graviton2 are priced about 20% lower per GB-second than x86. AWS says Arm functions can deliver up to 34% better price performance, though results depend on the workload and your code.
Tiered Duration Pricing
As your volume grows, duration gets cheaper automatically. According to AWS’s tiered pricing announcement, on x86, duration between 6 and 15 billion GB-seconds a month gets a 10% discount, and anything above 15 billion gets 20%. For Arm, the tiers start at 7.5 and 18.75 billion. The tiers apply per Region and per architecture, and they only matter at very high volume.
Cold Starts and INIT Billing
When Lambda creates a new execution environment, it runs an initialization (INIT) phase. Effective August 1, 2025, AWS standardized INIT billing, so INIT time is now included in the billed duration for on-demand invocations of ZIP functions on managed runtimes, at the normal duration price. Custom runtimes, provisioned concurrency, and container image functions were already billed for it.
AWS notes that cold starts typically happen in under 1% of invocations, so most customers see little impact. But heavy initialization code, large packages, and bursty traffic can make INIT time a real cost.
Provisioned Concurrency
Provisioned concurrency keeps environments warm so requests skip cold starts. You pay for the configured capacity by the GB-second whether or not requests arrive, and then pay a lower duration rate while those environments run requests. In US East (N. Virginia), AWS lists $0.0000041667 per GB-second for capacity on x86 and $0.0000097222 per GB-second for duration. We will do the break-even math soon.
Other Lambda Charges
- Ephemeral storage. Each function gets 512 MB of /tmp space, and you pay a small per GB-second price for more, up to 10,240 MB.
- SnapStart. AWS offers it to cut cold start time for supported runtimes, and it has its own pricing, so check the pricing page before enabling it.
- Lambda Managed Instances. This option runs functions on EC2 instances in your VPC. AWS lists $0.20 per million requests, plus the EC2 price, plus a 15% management fee on the On-Demand EC2 price, with no separate duration charge.
- Compute Savings Plans. They can reduce duration and provisioned concurrency charges by up to 17%, but not request charges.
Lambda Pricing Components at a Glance
| Component | How it is billed | AWS listed rate | Main lever |
| Requests | Per invocation | $0.20 per million | Filtering, batching |
| Duration (x86) | Per GB-second, 1 ms steps | $0.0000166667 in the first tier | Memory, code speed |
| Duration (Arm) | Per GB-second, 1 ms steps | $0.0000133334 in the first tier | Move to Arm |
| INIT phase | Included in billed duration | Standard duration rate | Smaller packages, SnapStart |
| Provisioned concurrency | Per GB-second of configured capacity | $0.0000041667 on x86 in US East | Right-size, schedule |
| Savings Plans | Commitment per hour | Up to 17% off duration | Steady usage |
Costs Around the Function
The Lambda line is often smaller than the charges around it:
- CloudWatch Logs. Every log line is ingested and stored, and charges apply per GB.
- API Gateway or load balancers. They charge per request or per hour, on top of Lambda.
- Data transfer and NAT gateways. Functions in a VPC that call the internet pay for NAT processing.
- Downstream services. DynamoDB, S3 requests, queues, and Step Functions all bill separately.
Any Lambda cost review should include these, or you may optimize the cheapest part of the bill.
How to Estimate and Monitor AWS Lambda Costs
You can predict most of a Lambda bill with a short spreadsheet, and you can watch it with a few built-in tools. Start with the estimate, then set up monitoring so surprises show up early.
How to Estimate Lambda Cost Step by Step
- Count invocations. Estimate requests per month for each function, including retries.
- Measure average duration. Use real timings from logs or a test, not guesses.
- Note the memory setting. Convert megabytes to gigabytes by dividing by 1,024.
- Calculate GB-seconds. Multiply memory in GB by duration in seconds by invocations.
- Subtract the free tier. Take off 400,000 GB-seconds and 1 million requests across your account.
- Apply the rates. Use the per GB-second price for your architecture and $0.20 per million requests.
- Add the neighbors. Include logs, API Gateway, data transfer, and downstream services.
You can also model a full architecture in the AWS Pricing Calculator.
Worked Example 1: A Busy API Function
This example uses AWS’s published rates for the first pricing tier. It assumes 10 million requests a month, 512 MB of memory, and an average duration of 200 ms.
- GB-seconds: 10 million × 0.2 seconds × 0.5 GB = 1,000,000.
- After the free tier: 600,000 billable GB-seconds.
- Duration on x86: 600,000 × $0.0000166667 = $10.00.
- Requests: 9 million billable × $0.20 per million = $1.80.
- Total on x86: about $11.80 a month.
On Arm, the same duration costs 600,000 × $0.0000133334, or $8.00, so the total falls to about $9.80. That is a saving of about $2 here, and it scales directly with volume.
Worked Example 2: More Memory, Lower Cost
This example is hypothetical, to show the idea. Suppose a CPU-bound function takes 800 ms at 512 MB. At 1,769 MB, which gives it a full vCPU, it takes 200 ms.
- At 512 MB: 0.5 GB × 0.8 seconds = 0.4 GB-seconds, or about $0.00000667 per run.
- At 1,769 MB: 1.7275 GB × 0.2 seconds = 0.3455 GB-seconds, or about $0.00000576 per run.
The larger setting is about 14% cheaper per run and four times faster. Many real functions do not scale this neatly, which is why you measure instead of assuming.
Worked Example 3: Provisioned Concurrency
Another hypothetical: 10 environments with 1 GB each, kept warm all month. That is 10 × 1 GB × 730 hours × 3,600 seconds, or 26.28 million GB-seconds. At $0.0000041667 per GB-second, the capacity alone costs about $109.50, before any requests or duration charges. We will look at when that is worth it in the next section.
Monitor Lambda Spend With Built-In Tools
Estimates drift, so watch the real numbers.
- Cost Explorer. Filter by the Lambda service and group by usage type to separate request charges from GB-second charges.
- Cost allocation tags. Tag functions by team, service, and environment, then activate the tags in billing so Cost Explorer can group by them.
- AWS Budgets and Cost Anomaly Detection. Set alerts on Lambda spend, so a runaway loop shows up in days, not weeks.
- CloudWatch metrics. Track invocations, duration, errors, throttles, and concurrent executions for each function.
- CloudWatch Lambda Insights. Adds system level metrics, such as memory and initialization time, for functions where you enable it.
- AWS Compute Optimizer. It can recommend memory settings from your usage history, though AWS notes it supports only x86_64 functions.
Find Over-Provisioned Functions With Logs Insights
Every invocation writes a REPORT line with the configured memory, the memory used, the billed duration, and the initialization time. A CloudWatch Logs Insights query can summarize them:
filter @type = “REPORT”
| stats count(*) as invocations,
avg(@billedDuration) as avgBilledMs,
avg(@initDuration) as avgInitMs,
max(@maxMemoryUsed / 1024 / 1024) as maxUsedMB,
avg(@memorySize / 1024 / 1024) as configuredMB
by bin(1d)
If the maximum memory used is far below the configured memory, you may be paying for capacity you do not need. Keep in mind that lowering memory also lowers CPU, so test the duration before you change anything.
How to Reduce AWS Lambda Costs: The Main Levers
These levers are ordered roughly by how often they pay off. Start at the top, measure after each change, and keep reliability ahead of savings.
1. Right-Size Memory With Real Measurements
AWS calls memory the principal lever for controlling a function’s performance, and recommends 128 MB only for simple functions that transform or route events. Everything else deserves a test.
Two tools help:
- AWS Lambda Power Tuning. An open source tool, linked from AWS’s memory documentation, that uses Step Functions to run your function at several memory sizes and graph cost against speed.
- AWS Compute Optimizer. It recommends memory settings from usage history, for x86_64 functions.
Test with realistic payloads. Functions that wait on a database or an API usually gain little from extra CPU, while CPU-bound work such as parsing, compression, and image processing often speeds up a lot.
2. Move Compatible Functions to Arm
Arm duration costs about 20% less than x86, and AWS cites up to 34% better price performance. Many functions in Node.js, Python, and Java move with little more than a configuration change. Functions with native dependencies or compiled libraries need testing and sometimes a rebuild.
Roll it out gradually. Switch one function, compare duration and errors for a week, then continue. Keep in mind that Compute Optimizer does not cover Arm functions, so measure those with Power Tuning.
3. Make Each Run Shorter
Billed duration includes time spent waiting, so every slow call you wait on is money. Ways to shorten runs:
- Create SDK clients and database connections outside the handler, so warm environments reuse them.
- Load only the libraries you need. AWS’s INIT billing article recommends smaller packages, and modular SDKs, to cut start time.
- Run independent downstream calls in parallel, not one after another.
- Set a realistic timeout. A function that hangs for 15 minutes on every failure is expensive.
- Return early when a request is invalid, before any slow work.
Since INIT time is now billed for on-demand ZIP functions on managed runtimes, trimming initialization code helps both speed and cost.
4. Invoke Less Often
The cheapest invocation is the one that never happens.
- Filter events. For SQS, Kinesis, and DynamoDB Streams, event source mappings can filter records before your function runs. AWS’s own example drops the cost of a telemetry workload from $4.59 to $0.15 a month, a 96.7% reduction, by filtering out records the function would have ignored anyway.
- Batch records. Raise the batch size and set a batching window, so one invocation handles many messages. Match the window to your latency needs.
- Avoid chains. When one function calls another and waits, you pay for both while they run. Use queues, Step Functions, or direct service integrations instead.
- Cap retries. Asynchronous invocations retry on failure, so set sensible retry limits and use dead-letter queues for poison messages.
- Prevent loops. A function that writes to the bucket or queue that triggers it can run away. Use AWS’s recursive loop detection and budget alerts as backstops.
Filtered records are still read from the source, so filtering saves Lambda charges and not queue or stream costs.
5. Use Provisioned Concurrency Carefully
Provisioned concurrency solves a latency problem, not a cost problem. It can also lower duration cost, but only if the environments stay busy.
Here is the break-even math using AWS’s US East rates for x86. Capacity costs $0.0000041667 per GB-second, or $0.015 per GB-hour. Duration on provisioned capacity is $0.0000097222 per GB-second, or $0.035 per GB-hour of busy time, compared with $0.06 on demand. If utilization is u, provisioned costs 0.015 + 0.035u and on demand costs 0.06u. They are equal at u = 0.015 ÷ 0.025, or 60%.
That means provisioned environments need to be busy more than about 60% of the time to cost less than on-demand. Below that, you are paying for latency, which may still be worth it. Ways to keep it cheaper:
- Provision only for functions where cold starts hurt users.
- Use scheduled scaling to raise capacity at peak hours and lower it at night.
- Never leave provisioned concurrency on dev and test functions or on old versions.
- Try SnapStart first, where your runtime supports it, since AWS service it reduces cold start latency and INIT costs.
6. Use Reserved Concurrency as a Guardrail
Reserved concurrency caps how many copies of a function can run at once. It has no extra charge. It protects downstream databases and acts as a ceiling on a runaway function, since a function cannot spend what it cannot run.
7. Tame Logging Costs
For chatty functions, CloudWatch Logs can cost more than compute. To trim it:
- Set a retention period on every log group, since the default is to keep logs forever.
- Use Lambda’s advanced logging controls to filter by log level, and run production at INFO or WARN.
- Do not log full request and response bodies unless you are debugging.
- Prefer metrics over log lines for numbers you chart.
8. Rethink the Architecture
Sometimes the biggest saving is not running a function at all.
- Connect API Gateway, EventBridge, or Step Functions directly to services such as DynamoDB, SQS, and S3 where they support it.
- Put CloudFront or API caching in front of read-heavy endpoints.
- Compare API Gateway HTTP APIs with REST APIs, since AWS prices them differently.
- Keep functions out of a VPC unless they need private resources, and use gateway endpoints for S3 and DynamoDB to avoid NAT charges.
9. Commit With Compute Savings Plans
AWS says Compute Savings Plans can cut Lambda duration and provisioned concurrency charges by up to 17% on one or three year commitments. They do not apply to requests. Commit only to the steady baseline you are sure to use, after you have made the optimizations above, or you may lock in waste.
10. Know When Lambda Is Not the Cheapest Option
Lambda charges for every second a function runs, so a function that is busy most of the day can cost more than the same work on an always-on instance. As a rough guide, one GB of memory running continuously for a month is 2,628,000 GB-seconds, which costs about $43.80 at the x86 on-demand rate.
For steady, predictable traffic, AWS’s guidance on reducing Lambda cost suggests Lambda Managed Instances, which run functions on EC2 instances in your VPC. You pay $0.20 per million requests, the EC2 price, and a 15% management fee, and you can use EC2 Savings Plans and Reserved Instances on the instance. Compare that with containers or instances for your own workload before you move.
The Levers Side by Side
| Lever | Typical effect | Effort | Main trade-off |
| Right-size memory | Often lowers duration cost | Low | Needs testing |
| Move to Arm | About 20% lower duration price | Low to medium | Native dependencies |
| Shorter runs | Lower GB-seconds | Medium | Code changes |
| Event filtering | Up to 96.7% in AWS’s example | Low | Filters must be correct |
| Batching | Fewer requests and cold starts | Low | Added latency |
| Provisioned concurrency | Better latency, sometimes lower cost | Low | Pays when idle |
| Savings Plans | Up to 17% on duration | Low | Commitment risk |
| Managed Instances | Lower unit cost at steady load | High | Different operating model |
A Step by Step Lambda Cost Optimization Plan
You do not need to fix every function. Focus on the few that drive most of the bill.
- Find the top spenders. In Cost Explorer, group Lambda charges by tag or function, and list the top ten.
- Split requests from duration. Check which charge dominates, since it decides your first move.
- Check the neighbors. Review CloudWatch Logs, API Gateway, NAT, and downstream costs for the same workload.
- Measure memory and duration. Use Logs Insights and Power Tuning to compare settings with realistic payloads.
- Cut invocations. Add event filters, raise batch sizes, remove function chains, and cap retries.
- Move to Arm. Test one function at a time, and compare errors and duration before you roll out.
- Review provisioned concurrency. Remove it where it is idle, schedule it where traffic is predictable, and try SnapStart first.
- Tame logs. Set retention, lower the log level in production, and stop logging large payloads.
- Commit last. Buy a Compute Savings Plan for the stable baseline once usage has settled.
- Set guardrails. Add budgets, anomaly alerts, and reserved concurrency limits, and review spend monthly.
Set Guardrails So Costs Do Not Creep Back
Optimization decays unless something protects it. A few habits help:
- Tag every function with a team, service, and environment, so spend has an owner.
- Alert on spend and on invocations, since a loop can multiply a bill overnight.
- Set reserved concurrency on functions that call fragile or expensive downstream systems.
- Review new functions for memory, architecture, timeout, and log settings before they ship.
- Run a monthly review of the top spenders and any provisioned concurrency.
Common Lambda Cost Optimization Mistakes
- Leaving every function at 128 MB or at 1 GB. Neither default fits all workloads, and only measurement finds the right setting.
- Lowering memory without testing duration. Less memory means less CPU, so a function can get slower and cost more.
- Using provisioned concurrency as a cure-all. It adds cost when environments sit idle.
- Ignoring logs. Debug logging left on in production can cost more than compute.
- Chaining functions synchronously. You pay for the waiting caller and the working callee together.
- Skipping event filters. Functions that discard most events still bill for each invocation.
- Buying Savings Plans too early. Commit after optimizing, or you may lock in inefficiency.
- Forgetting the rest of the stack. API Gateway, NAT gateways, and downstream services often cost more than the function.
- Optimizing once. Traffic and code change, so measure again each quarter.
One honest limit applies. Savings depend on your workload, and AWS’s percentages are maximums, not promises. Test each change in a lower environment, and watch errors and latency alongside cost.
Decision Guide: Where Should You Start?
- Your bill is mostly requests: add event filtering, batching, and caching in front of the function.
- Your bill is mostly duration: tune memory, shorten runs, and move to Arm.
- Your logs cost as much as compute: set retention and lower log levels first.
- Cold starts hurt users: try SnapStart and smaller packages before paying for provisioned concurrency.
- You have steady, heavy traffic: compare Savings Plans and Managed Instances against your current cost.
- You are a startup with low volume: lean on the free tier, keep functions simple, and set budget alerts.
- You are not sure where the money goes: tag functions and start with Cost Explorer.
Numbers Worth Remembering
Keep this short list in mind. Each figure comes from AWS’s pricing and guidance, so confirm current values for your Region.
- $0.20 per million requests.
- $0.0000166667 and $0.0000133334 per GB-second for x86 and Arm in the first tier.
- 1 million requests and 400,000 GB-seconds free every month.
- 1,769 MB gives a function the equivalent of one vCPU .
- Up to 17% off duration and provisioned concurrency with Compute Savings Plans.
- About 60% utilization is the break-even point for provisioned concurrency in US East on x86.
- August 1, 2025 is when INIT billing was standardized for managed runtime ZIP functions.
Practical Examples
These scenarios are illustrative, not real customer cases.
The noisy queue. A team processes every message from a shared queue, but its function only acts on a small share of them. After adding an event filter, the function stops running for the rest, and request and duration charges fall sharply.
The oversized logs. A startup finds that its log ingestion cost rivals its compute cost, because each request logs the full payload. Lowering the production log level and setting a 14 day retention shrinks the bill without changing any application logic.
The idle warm pool. A team enables provisioned concurrency on dozens of functions after one slow launch. A review shows most sit idle overnight. They keep it only on two customer-facing functions and schedule it down after hours.
Conclusion
Lambda cost optimization is mostly about measurement and a few well chosen habits. Know what you pay for, find the functions that matter, and tune memory, architecture, and invocations before you consider commitments. Then add guardrails so the savings stay.
Start this week by tagging your functions and listing the ten most expensive ones in Cost Explorer. Once you can see them, the first fix is usually clear.