Skip to content

Missing location headers from cloudfront to lambda function

0

Before the Nov 23 my headers included these fields , now they do not. I have not changed anything on my end. Has there been a service change regarding these fields in cloudfront?

"CloudFront-Viewer-Latitude": "40.xyz", "CloudFront-Viewer-Longitude": "-80.xyz", "CloudFront-Viewer-Metro-Code": "999", "CloudFront-Viewer-Postal-Code": "11111", "CloudFront-Viewer-Time-Zone": ".....",

asked 9 months ago317 views

2 Answers
0

I'm experiencing the same issue. I have one cloudfront with the "AllViewerExceptHostHeader" with an ApiGateway as origin with protocol HTTP where the headers are forwarded correctly. And then I have another CloudFront with an ApiGateway as origin with protocol REST where the headers are not forwarded. Same setup, different protocol for ApiGateway.

I can see the header in the viewer request event in CloudFront and I can re write them there to a custom header and then I can access the custom headers in my lambda. So it's not true that they are only present in the Lamdba@Edge (origin request and origin response).

This stopped working around the 23rd november and I haven't made any changes to my code or setup. I can probably look in my logs for an exact date. Please let me know if you need any additional information to troubleshoot and when there is a fix for this.

answered 8 months ago

-1

If you're no longer receiving CloudFront viewer location headers like CloudFront-Viewer-Latitude, CloudFront-Viewer-Longitude, CloudFront-Viewer-Metro-Code, CloudFront-Viewer-Postal-Code, and CloudFront-Viewer-Time-Zone in your Lambda function, there are a few important things to check.

These headers are not automatically included in requests to your origin or Lambda functions. You need to explicitly configure CloudFront to add them using either a cache policy or an origin request policy. If these headers were working before November 23 and suddenly stopped working without any changes on your end, you should verify:

  1. That your origin request policy or cache policy still includes these specific headers
  2. That the policy is still properly attached to your CloudFront distribution behavior

It's worth noting that CloudFront adds these headers after the viewer request event, which means they're only available to Lambda@Edge functions in origin request and origin response events, not in viewer request events.

Also, CloudFront only applies these location headers to requests that don't originate from the AWS network. If your traffic patterns have changed and more requests are coming from within the AWS network, this could explain why you're seeing fewer of these headers.

If your configuration appears correct, you may want to contact AWS Support as there haven't been any announced changes to this functionality.
Sources
How do I make CloudFront request headers available in my edge compute functions? | AWS re:Post
Restrictions on Lambda@Edge - Amazon CloudFront
Add CloudFront request headers - Amazon CloudFront

answered 9 months ago

EXPERT

reviewed 9 months ago

  • My cache policy is disabled, my origin policy is Managed-AllViewerExceptHostHeader. It is the only and default behavior. I am making the requests from residential isp as well as commercial vpn clients, and the fields are missing in both cases.

    Also i am not using lambda@edge. The origin is apigateway backed by lambda

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.