Retrieve clients geolocation info from AWS ELB

amazon-elbamazon-web-services

We want to be able to identify what country our users are coming from when visiting our site. I know ELB supports the Proxy protocol and will send through the client's IP; which I could use to do a IP geo-lookup manually. But does ELB have anything built into it that would tell me how to get the user's location info, perhaps through a header? Don't need much info, just the client's country.

Best Answer

ELB does not offer this capability. Cloudfront, however, does. Amazon CloudFront Adds Device Detection, Geo Targeting, Host Header Forwarding, CORS Support, and more!

You could use CloudFront in front of your ELB (configuring the ELB as a "custom origin") and then enable the Cloudfront-Viewer-Country header, which does two things: allows you to know the geolocation lookup result, and causes Cloudfront to keep a country-specific cache of every cacheable resource (so cached responses still behave on a country-specific basis.)

You can also enable headers that will identify the browser as desktop, mobile, tablet, or smart television.

Look closely at the fine print of the pricing structure and you will find that in some cases (depending on the country, configuration, and traffic volume) using CloudFront in front of EC2 can actually be almost $0.005/GB less expensive than not using it, as strange as that seems, due to recent price structure changes.