Skip to content

Instantly share code, notes, and snippets.

@diegofcornejo
Created October 15, 2022 03:11
Show Gist options
  • Save diegofcornejo/19abb1ffb5d73908875ba298ed7cf54a to your computer and use it in GitHub Desktop.
Save diegofcornejo/19abb1ffb5d73908875ba298ed7cf54a to your computer and use it in GitHub Desktop.
AWS Lambda - Validate if domain point to specific IP's
const dns = require('dns');
const ips = ["XX.XX.XX.XX", "XX.XX.XX.XX"];
exports.handler = (event, context, callback) => {
// context.callbackWaitsForEmptyEventLoop = false;
let body = JSON.parse(event.body);
var done = function(code, message) {
let response = {
"statusCode": code,
"body": JSON.stringify(message)
};
callback(null, response);
};
dns.lookup(body.domain, (err, address, family) => {
if (err) {
done(500, err);
}
if (address) {
var exist = ips.includes(address);
if (exist) {
done(200, 'configured');
}
else {
done(404, 'not configured');
}
}
else {
done(404, 'not configured');
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment