Created
October 15, 2022 03:11
-
-
Save diegofcornejo/19abb1ffb5d73908875ba298ed7cf54a to your computer and use it in GitHub Desktop.
AWS Lambda - Validate if domain point to specific IP's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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