Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Filtering AWS IP Ranges

node v10.24.1
version: 1.0.0
endpointsharetweet
AWS provide IP ranges for their services, in case you'd like to add another layer of security via IP whitelisting. They are available from https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html, but can be a pain to parse, so let's do that here! First, we'll fetch the data:
const getJSON = require("async-get-json") const prefixes = (await getJSON("https://ip-ranges.amazonaws.com/ip-ranges.json")).prefixes
My last run of this command returned over a thousand results 😲 Let's filter that dynamically with a parameterised endpoint:
const url = require("url") exports.endpoint = (request, response) => { const query = url.parse(request.url, true).query const region = new RegExp(query.region || ".*") const service = new RegExp(query.service || ".*") const filtered = prefixes.filter(prefix => region.test(prefix.region) && service.test(prefix.service)) response.setHeader("Content-Type", "application/json") response.end(JSON.stringify(filtered)) }
Now, you can hit the endpoint link at the top of this page, and pass regexes such as ?region=us.*&service=CLOUD9 to it, to find all Cloud 9 IP ranges in the US. Much better 🤓
Loading…

no comments

    sign in to comment