Lambda Edge in Origin request does not trigger at edge location but at regional edge location even when behaviour caching policy is CachingDisabled

0

I am not sure if this is intended, is a default behaviour, has a configuration or possibly a hack. I have some requests originating from within the Saudia Arabia and UAE region, and a frontend and backend that sit under the same domain through cloud front and i handle the routing through the path pattern where the website sits on a s3 behind one pattern and the other path pattern sends requests to the backend. Before sending the request to backend, however, an Edge Lambda is invoked as a reverse proxy and path rewriter. However, when i check Function Metrics from under Cloud Front Telemetry Monitoring for the Edge Lambda, i see that nearly all of the invocations lie in Frankfurt or Ireland. Based on the map here https://aws.amazon.com/cloudfront/features/?whats-new-cloudfront.sort-by=item.additionalFields.postDateTime&whats-new-cloudfront.sort-order=desc i would expect the invocations to be within the Saudia/UAE region and but instead i see the invocations in the Frankfurt region from where it is then sent to the backend which is at Mumbai leading to a longer trip. On searching up a bit I found that there is a concept of Regional Edge Locations as well which act as the second layer of cache after the edge location and all my invocations lie there. To somehow get the Lambdas to trigger at the edge locations instead of regional i tried setting the Cache Policy to CacheDisabled, legacy cache settings to All Headers and some hacks like setting the max age and expire headers in the api requests but the invocations consistently lie at their previous locations.

asked 8 months ago297 views
3 Answers
0
Accepted Answer

Hello,

For simple operation you can try to leverage Cloudfront functions which operates at edge. You can get support from this blog which details the difference with lambda and it could help you to find a solution.

https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/

AWS
answered 8 months ago
profile picture
EXPERT
reviewed 10 days ago
  • Thanks, I hadn't come across anything yet that explicitly stated that Edge Lambdas are executed at regional edge caches only but had a guess that this might be the case

0

I am assuming you are talking about Origin Edge Lambdas.

You should do below:

  1. Setup Origin Shield on the Origin in the Cloudfront
  2. Mark the origin region for the origin shield as UAE Henceforth all origin lambda executions would be triggered in the UAE region. This is because Origin Shield forces all Origin Lambda calls to execute at the shield origin region
Anand
answered 2 months ago
  • Thanks we were able to drop our API times by 200 to 250 ms by enabling origin shield and setting it to be in the same region as our Backend, Mumbai.

  • @rayyan happy to know it has helped you. Please upvote if you found my answer helpful. Thanks

0

Lambda@edge are invoked at 'Regional Edge Cache'[1], and the 'Regional Edge Cache' might not be the same location as the 'PoP'. Therefore, a possible alternative is to have your logic run in CloudFront Functions, which would be invoked in the 'PoP' where the traffic lands. ( Just like 'AWS-User-7455027' mentions)

You may also check the following article to understand more about them.

[1] https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/

Lambda@Edge functions are executed in a regional edge cache (usually in the AWS region closest to the CloudFront edge location reached by the client)
profile pictureAWS
Kenex_H
answered 8 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