Filtering AWS IP Ranges

node v10.15.3
version: 1.0.0
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, 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("")).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 🤓

no comments

    sign in to comment