serverless-geoip
serverless-geoip copied to clipboard
Use MaxMind GeoLite2 database with AWS Lambda
Serverless GeoIP
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.
Install
$ > git clone [email protected]:sbstjn/serverless-geoip.git
$ > cd serverless-geoip
$ > yarn install
Configure
Download the GeoLite2 City database and store the file inside the data
folder.
.
└── data
└── GeoLite2-City.mmdb
Deploy
$ > yarn deploy
…
endpoints:
GET - https://randomid.execute-api.us-east-1.amazonaws.com/dev/ip/{ip}
Usage
Invoke
$ > 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",
…
…
HTTP Request
$ > 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", …