CloudFront Lambda Edge Cost


Hello everyone,

I have a question regarding the CloudFront high cost that I encountered few days ago.

I have different accounts and the CloudFront costs are normal. I have a lambda edge functions for enhancing the default functionalities and improve the security of a website.

But on one particular account I have a very high requests for lambda edge over 24 000 000 Lambda-GB-Second and it is causing excessive bills.

The app is on S3 bucket only and the redirection is made based on locale (for every user we fetch viewer-location to redirect).

Thanks in advance

  • After some time I managed to solve this problem.

    The solution was pretty simple, the lambda edge function was setup to redirect to 404/index.html, and when it got triggered it tried to look up for this page in the S3 bucket (I didn't had this path in S3), so it created immense amount of requests. It all went back to normal after I created this index.html.

asked 2 months ago105 views
2 Answers
Accepted Answer


In addition to what @Hari Priya has suggested, I suspect your lambda calls may be triggering redirects as well. You may be in certain cases triggering way too many redirects to yourself causing unnecessary invocation. You would need to investigate and stop such infinite loops. Its possible to add a counter cookie and terminate the loop on a threshold etc

answered 2 months ago
profile picture
reviewed a month ago
  • I found that there are excessive requests to 404/index.html. Shall I try and remove this part from edge function so it doesn't call it self. I saw that all IPs are coming from Amazon. What would be the best solution here?

    Thanks in advance


1)Analyze Lambda@Edge Usage: Review your Lambda@Edge functions to understand how they are being invoked and how frequently. Determine if there are any patterns or specific events that are triggering excessive invocations. Use AWS CloudWatch metrics to monitor Lambda@Edge usage and identify any spikes or anomalies.

  1. Review Lambda@Edge Function Code: Examine the code of your Lambda@Edge functions to ensure they are optimized for performance and cost efficiency. Look for any inefficiencies, such as unnecessary computations or excessive resource usage. Consider implementing caching mechanisms or optimizing code logic to reduce execution time and resource consumption.
3)Check CloudFront Configuration: 

Review your CloudFront distribution configuration to ensure it's properly configured and optimized. Evaluate cache behavior settings, origin configurations, and cache key settings to maximize caching effectiveness and minimize the need for frequent Lambda@Edge invocations.

  1. Evaluate Viewer Request Processing: Since you mentioned using Lambda@Edge for locale-based redirection, assess the logic for processing viewer requests. Determine if there are alternative approaches or optimizations that can achieve the desired functionality with fewer Lambda@Edge invocations.

  2. Monitor and Adjust: Continuously monitor Lambda@Edge usage and associated costs using AWS Cost Explorer or billing dashboards. Implement alarms and notifications to alert you of any sudden spikes in usage. Adjust your configurations and optimizations as needed to optimize costs while maintaining functionality.

6)Consider Cost Allocation Tags: 

Utilize cost allocation tags to track Lambda@Edge costs and attribute them to specific resources or projects within your AWS account. This can help you identify cost-intensive components and better allocate resources in the future.

profile picture
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions