Use AWS Lambda and MaxMind GeoLite to query for locations of IP addresses. You can invoke the function or use API Gateway to send an HTTP request with the IP address to lookup.
$ > git clone git@github.com:sbstjn/serverless-geoip.git
$ > cd serverless-geoip
$ > yarn install
Download the GeoLite2 City database and store the file inside the data
folder.
.
└── data
└── GeoLite2-City.mmdb
$ > yarn deploy
…
endpoints:
GET - https://randomid.execute-api.us-east-1.amazonaws.com/dev/ip/{ip}
$ > sls invoke -f lookup --data '{ "ip": "8.8.8.8" }'
{
"continent": {
"code": "NA",
"geoname_id": 6255149,
"names": {
"de": "Nordamerika",
"en": "North America",
"es": "Norteamérica",
…
…
$ > curl https://randomid.execute-api.us-east-1.amazonaws.com/dev/ip/8.8.8.8
{"continent":{"code":"NA","geoname_id":6255149,"names":{"de":"Nordamerika","en":"North America", …