A repository of tips and tricks (in both English and French) curated by Mirego’s engineering team.
  • aws

How to get the user’s location via CloudFront

Today I learned that it’s possible to get the user’s current location via special headers when calling CloudFront.

All you have to do is:

  1. Go to your CloudFront distribution, then go to the "Policies" section
  2. Add an "Origin request policy"
  3. Inside the policy, under "Origin request contents" you can add the CloudFront-Viewer-Latitude and CloudFront-Viewer-Longitude headers

Voilà! Whenever you call that CouldFront distribution, you’ll have the headers with the user’s current location!

Those are the two that I needed for my use case but CloudFront actually exposes a lot more headers that you can use to get details about the user, you can read more about it on this page.