Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
list cloufront ip ranges for nginx real ip module
var request = require("request");
var fs = require("fs");
var output = "#cloudfront ip ranges\n";
request("https://ip-ranges.amazonaws.com/ip-ranges.json", function(err, res, body) {
if (err) {
console.error("error", err);
}
var j = JSON.parse(body);
j.prefixes.forEach(function(item) {
if (item.service ==='CLOUDFRONT') {
output += "set_real_ip_from " + item.ip_prefix + ";\n"
}
})
fs.writeFileSync(__dirname + "/etc/cloudfront_ips", output);
console.log("write cloudfront ips");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment