0

In the AWS CloudFront distribution, I can configure the origin request policy to add CloudFront-Viewer-Country header to the origin request, and I can read that header in the Lambda@Edge attached to the origin request or origin response. However, that header is cached, and there are edge servers only in 50 countries.

What I need is to run Lambda@Edge so that it adds the CloudFront-Viewer-Country header to the viewer response, which is attached to the viewer response event. In this case, header alteration happens after the CloudFront reads the response from the cache; thus, the response sent to each viewer will have an accurate CloudFront-Viewer-Country. I also assume that the viewer response lambda does not miss the cache, just because I need a unique header to be added to the viewer response in that cache.

One ugly solution is referring to ipinfo.io from a Lambda@Edge attached to the viewer response event. And it works. I wonder if there is a way to avoid that and refer to CloudFront-Viewer-Country, which CloudFront has anyway.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.