Refactoring and deploying & REST API on AWS

Yassine Aboukir · April 18, 2022 is a small service that provides data and insights into ASN (Autonomous System) numbers. The latter is a globally unique 16 digit identification number assigned to an entity or organization and points to a set of internet routable IP prefixes that belong to them. For example, AS32934 belongs to Facebook and defines a number of IPv4 and IPv6 that are registered and owned by them.

ASNLookup service has been around for over 4 years now and I’ve initially built it for security researchers to help them with reconnaissance by identifying IP spaces owned by specific organizations. The service was widely used either through the website, python wrapper or the API endpoint I made available for free. I was running it free of charge which was a bit costly, but at one point in time, it started going down regularly because of companies that were abusing the API that I initially set up for individuals and researchers.

The backend was nothing fancy at all! It was a simple CSV file as a database and a Flask application with one view and python data processor. For the most part, Linux OOM Killer would always terminate the application process when it was running out of memory and can’t handle that much traffic coming from these companies.

Yet, to my surprise, this little service has actually received a sponsoring and acquisition offer from a renowned company dealing in IP and geolocation data. I couldn’t believe someone would be interested in it but I had a feeling it wouldn’t be an interesting offer so it wasn’t worth it, hence I respectfully declined the offer and informed them of my plan to build it out which I, unfortunately, haven’t done.

Fast forward two years, I decided to take it as a fun project so it was time to refactor the codebase and properly build the service as API-as-a-Product to get rid of these greedy companies abusing the free API, or at least monetize it so that it covers, at least, its hosting costs. It was also an opportunity for me to leverage my new acquired knowledge in software engineering and test out Amazon web services as well to become more familiar with.

The new refactored version of ASNLookup API is serverless and leverages additional data sources. It uses Django REST framework that was separately deployed on a Lambda function with AWS API gateway set up to trigger and route HTTP requests to it. The API gateway allows me to secure the endpoint by requiring an API key to be sent as part of HTTP request headers. And the deployment process was fortunately smooth and easy thanks to Zappa which handles all configurations and allows quick updates with a single command.

Since I have no desire to handle payments and billing data nor do I want to spend time building it, I decided to use RapidAPI service to allow users to subscribe to the API and make it available in their API marketplace.

Regarding the database, it uses PostgreSQL whcih was separately hosted on AWS RDS, not to overload the main servers. It was relatively quick and intuitive set up and connect to it but you must be careful with security configurations when you expose the instance publicly.

The main web application is also built with Django and hosted separately on EC2 but I think Amazon pricing for these instances is a bit on the expensive side given the low specs they offer and compared to other cloud providers such as DigitalOcean and Hetzner which I currently use for other projects. I tried to host it elsewhere but the latency was extremely high when I started migrating data from Hetzner server hosted in central EU to AWS RDS in east US - it was ridiculously slow! I assume part of it was caused by the distance between the data centers but it was still unreasonable, therefore I had to switch back to EC2.

Although I used Django internal caching mechanisms to make the application run faster, I also put up Cloudflare CDN in the front to handle traffic and to add an additional security layer but the free DNS level SSL provided was also the cherry on top.

So I’d like present you the new ASNLookup service available at

Twitter, Facebook