Christine
Christine

Reputation: 3064

How to get the CloudFront endpoint country of a client request?

My website is hosted in S3 and a CloudFront Distribution is pointing to it.

In my website I need to know from which country the request for my website comes from.

Is there a way for CloudFront to add this information based on the CloudFront endpoints location to the request, maybe as a header or so?

Upvotes: 1

Views: 3321

Answers (1)

ceejayoz
ceejayoz

Reputation: 180024

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html

If you want CloudFront to cache different versions of your objects based on the country that the request came from, configure CloudFront to forward the CloudFront-Viewer-Country header to your origin. CloudFront automatically converts the IP address that the request came from into a two-letter country code. For an easy-to-use list of country codes, sortable by code and by country name, see the Wikipedia entry ISO 3166-1 alpha-2.

Upvotes: 4

Related Questions