Are you paying thousands of dollars for running Lambda functions in your AWS accounts. That's a common scenario where you start of Lambda functions as it is cheap but over time when you invoking the Lambda thousands of times, your bills just go high and you can't figure out how to reduce it. In this article, I will talk about steps you can take to reduce the cost.
Identify Source of Cost
Before we can reduce the cost, we need to understand where the cost is coming from. Let's go through a few metrics.
-
Invocations:
- How often are the Lambda functions being called?
- Is the architecture correct?
- Do you need to call it that often.
-
Duration:
- How long are the functions ru...
Are you paying thousands of dollars for running Lambda functions in your AWS accounts. That's a common scenario where you start of Lambda functions as it is cheap but over time when you invoking the Lambda thousands of times, your bills just go high and you can't figure out how to reduce it. In this article, I will talk about steps you can take to reduce the cost.
Identify Source of Cost
Before we can reduce the cost, we need to understand where the cost is coming from. Let's go through a few metrics.
-
Invocations:
- How often are the Lambda functions being called?
- Is the architecture correct?
- Do you need to call it that often.
-
Duration:
- How long are the functions running for each invocations?
- Does it need to run for so long?
- You can optimise but updating the memory configuration which allow the Lambda to run faster.
-
Memory configuration:
- Have you allocated more than needed?
You can also enable AWS X-Ray or Lambda Power Tuning to visualize resource usage and duration.
Right-Size Memory and CPU
Lambda charges based on memory × duration. Increasing memory increases CPU proportionally — but beyond a certain point, you're just paying for idle CPU.
How to optimize:
Use AWS Lambda Power Tuning (by AWS Labs) — it runs tests across different memory configurations.
Find the sweet spot: the smallest memory size that keeps execution time fast enough.
For example: Sometimes downgrading memory from 512 MB to 256 MB doubles runtime but cuts cost 30–40%.
Reduce Invocation Frequency
-
Batch events together when possible. For example:
- Use SQS batching instead of processing one message per invocation.
- For Kinesis or DynamoDB Streams, increase the batch size.
Add filtering on triggers instead of Lambda (e.g., event filtering for S3 or DynamoDB Streams).
If Lambda is used for
cronjobs, ensure they run only when needed.
Avoid “Always On” Patterns
If your function runs continuously or frequently:
Consider AWS Fargate or ECS for long-running processes. That is, run Fargate or ECS continuously instead of invoking Lambda functions.
For
high-throughputAPIs, consider ECS + ALB or API Gateway + ECR container.For near-real-time streams, Kinesis Data Analytics or Glue streaming might be more cost-efficient.
Choose Cost Optimised Architecture
By default, most developers build Lambda functions using the Intel architecture, however, you can decrease the running cost by 20-30% by using the arm architecture.
- To use
arm, no code changes are needed if you use NodeJS or Python. - Minor .NET changes might be needed to use
armarchitecture.
Optimize Dependencies and Cold Starts
Cold starts can increase duration (and thus cost).
Use smaller deployment packages — avoid large dependencies. You can do so by using Lambda layers. This significantly reduces the size of your function's deployment package and allows for easier dependency management across multiple functions.
Prefer
AWS SDK v3modular imports.Use
Provisioned Concurrencyonly where latency is critical — otherwise it increases cost.
Use Savings Plan
Free Tier: 1M requests and 400,000 GB-seconds per month are free.
Compute Savings Plan: If Lambda is heavily used, a Savings Plan can cut costs by up to 17%–30%.
Regional pricing differences: Check if multi-region deployments make sense. For example, us-east-1 or eu-west-1 is much cheaper than eu-west-2 or ap-southeast-2.
Do/Don’t Run Lambda on VPC
There is no explicit fee for attaching a Lambda to a VPC. However, network configuration side effects can increase costs in these ways:
VPC data transfer: Data transfer charges can incur when traffic is sent between AZs
NAT Gateway data processing fees: If Lambda needs internet, it will use NAT Gateway which in turn will incur processing fees.
Conclusion
As you can see, there are many opportunities for you to reduce the cost of Lambda functions. You might be on different stages in your cost management exercises and choose the step that is more suitable to you.
If you have additional ways to save Lambda's running cost, please suggest in the comments. If this article helped you to reduce cost, let me know.