Giter Site home page Giter Site logo

aws-ip-range-api's Introduction

aws-ip-range-api

Table of Contents

What does it do

Sometimes you need to validate the source IP address in your applications. If you are running your workloads on AWS, you might need to validate if:

  • The IP address is an valid AWS IP
  • What AWS region that IP address belongs to
  • What is the service associated with the said IP address

If this is your use case, this project might help you.

It uses AWS API Gateway to provide you with an REST API to query an IP address. You can use this code to deploy your own API and integrate with your applications.

This project uses

Where does the information comes from

AWS provides a list of IP ranges in a json format. You can find the file here:

https://ip-ranges.amazonaws.com/ip-ranges.json

An example of how the file looks like:

    {
      "ip_prefix": "18.191.0.0/16",
      "region": "us-east-2",
      "service": "EC2",
      "network_border_group": "us-east-2"
    },

Get started

  • Install the Serveless Framework
  • Install the serverless-python-requirements plugin
sls plugin install -n serverless-python-requirements
  • Deploy the serverless architecture by running:
serverless --aws-profile <YOUR_PROFILE_NAME> deploy

Replace <YOUR_PROFILE_NAME> with your AWS profile name.

If the deployment is successful, you will see the API Gateway endpoints created:

  GET - https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/health/check
  GET - https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/{ip}
  GET - https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/{ip}/region
  GET - https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/{ip}/service

How to use it

Get all avaliable information for a valid AWS IP address

curl https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/18.228.93.48

Result:

{
  "data": {
    "ip_prefix": "18.228.0.0/16",
    "region": "sa-east-1",
    "service": "EC2",
    "network_border_group": "sa-east-1"
  }
}

Get the region of a valid AWS IP address

curl -vvvv https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/52.1.1.1/region

Result:

{
  "region": "us-east-1"
}

Get the service associated with a valid AWS IP address

curl https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/3.17.184.157/service

Result:

{
  "service": "EC2"
}

Get all avaliable information for a non-AWS IP address

curl https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/127.0.0.1

Result:

{
  "data": "unknown"
}

Get the region of a non-AWS IP address

curl https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/127.0.0.1/region

Result:

{
  "region": "unknown"
}

Get the service associated with a non-AWS IP address

curl https://qe0fnc7qn7.execute-api.us-east-2.amazonaws.com/prod/127.0.0.1/service

Result:

{
  "service": "unknown"
}

Clean up

  • Destroy the serverless architecture by running:
serverless --aws-profile <YOUR_PROFILE_NAME> remove

Notes

Running this code will create AWS resources in your account that might not be included in the free tier.

aws-ip-range-api's People

Contributors

groorj avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.