This is a simple Python handler for AWS Lambda to determine a user's geo-location based on their IP. To map IP's to countries (or cities if you choose), we use MaxMind's GeoLite2 database which can be downloaded here: https://dev.maxmind.com/geoip/geoip2/geolite2/
There are many ways to configure API Gateway to fit your needs. The minimum things you need to do to expose this lambda function are the following:
- Create a new resource and add a GET method
- To the Body Mapping Templates in the Integration Request add the following:
{
"requesterIp" : "$context.identity.sourceIp"
}
- Congrats! This is the minimal setup to request your lambda function through API gateway.