- Newest
- Most votes
- Most comments
The discrepancy between Lambda invocations and CDN requests you're observing is likely due to how AWS CloudFront (assuming this is the CDN you're using) interacts with Lambda@Edge functions.
When you use a Lambda function at the viewer request stage with caching disabled, it doesn't necessarily mean that the Lambda function will be invoked for every single request. AWS does indeed optimize invocations based on expected responses, especially for Lambda@Edge functions.
In your case, where the Lambda function returns the original request for certain subpaths, AWS can indeed cache this behavior internally. CloudFront has built-in optimizations to reduce the number of Lambda invocations when it determines that the function's output is likely to be the same for similar requests.
This optimization is particularly effective for functions that don't modify the request or only do so based on easily cacheable criteria (like specific URL paths). CloudFront can remember the result of previous Lambda invocations and apply the same modifications without invoking the Lambda function again for a period of time.
The fact that you're not seeing any throttled requests supports this explanation. If every single CDN request was trying to invoke the Lambda function, you'd likely see throttling during high-traffic periods like Black Friday.
It's important to note that while this behavior helps optimize performance and reduce costs, it doesn't affect the actual caching of the content served by the CDN. The content caching is still disabled as per your configuration.
This optimization is a feature of the AWS infrastructure and is not something you can directly control. However, it's generally beneficial as it reduces latency and costs while maintaining the intended functionality of your setup.
If you need the Lambda function to be invoked for every single request without exception, you might need to include some unique identifier or timestamp in each request to force CloudFront to invoke the function each time. However, this would likely increase your Lambda costs and potentially impact performance during high-traffic periods.
Sources
Comparing Lambda invocation modes - AWS Lambda
Comparing performance of interactive and asynchronous workloads - AWS Lambda
Invoke - AWS Lambda
Relevant content
asked 2 years ago
asked 2 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 4 years ago
- AWS OFFICIALUpdated 4 years ago
