AWS Lambda with MaxMind GeoLite2 IP database

November 3rd, 2017 • 136 Words

The MaxMind GeoLite2 database is basically the standard solution when you need to get the geo information for an IP address. Together with the mmdb-reader NPM package you can easily deploy your own serverless API to AWS Lambda to lookup locations for IP addresses.

Thanks to AWS Lambda the deployed function can be used by other Lambda functions, or via HTTP using Amazon’s API Gateway.

Configuration

Just clone the serverless-geoip project from GitHub and install the needed dependencies:

$ > git clone git@github.com:sbstjn/serverless-geoip.git
$ > cd serverless-geoip
$ > yarn install

Afterwards, download the GeoLite2 City database and store the file inside the data folder.

.
└── data
    └── GeoLite2-City.mmdb

Usage

You can now deploy the project with serverless and send HTTP requests using cURL to lookup the geographical location of an IP address:

$ > yarn deploy

…

endpoints:
  GET - https://randomid.execute-api.us-east-1.amazonaws.com/dev/ip/{ip}

$ > 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", …

First I thought about caching the result in a DynamoDB or Redis, but querying the database is fast enough for now …


View on GitHubSource code is published using the MIT License.
  • Deploy React SPA with CodePipeline and CodeBuild using AWS CDK

    January 23rd, 2020 • 748 Words

    There are plenty of tools and services for continuous delivery available. Most of them are either directly built into the source code management tools you already use, or perfectly integrate with them. You might be…

  • AWS re:Invent 2019 Recap & Videos

    December 15th, 2019 • 360 Words

    I was able to attend the AWS re:Invent 2019 conference. A week full of learning about current and new technologies, services, and general approaches is definitely overwhelming. There is no much content available, during…

  • CloudFormation Best-Practices

    May 1st, 2019 • 457 Words

    You can find plenty of frameworks and tools to provision your AWS resources. Some of them do a great job for a specific purpose, others are more generic. Nevertheless, I do prefer to use native CloudFormation templates…

  • Last Update: 2020-01-23T19:02:36.710Z
    Stresemannstraße 132, 22769 Hamburg
    +49 151 54 64 90 55
    inbox@sbstjn.com