Last active
January 12, 2019 12:15
-
-
Save zbjornson/83977b3ffa51072eee9b50933edd9285 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 name = "<some domain>"; | |
const AWS = require("aws-sdk"); | |
const route53 = new AWS.Route53(); | |
const DNS = require("@google-cloud/dns"); | |
const dns = new DNS({projectId: "<your project id>"}); | |
const dnsZone = dns.zone("<zone name>"); | |
const resolvers = [ // See note below -- set to the NS for your zone | |
"<dns server 1>", | |
"<dns server 2>"//, ... | |
].map(ip => { | |
const {Resolver} = require("dns"); | |
const resolver = new Resolver(); | |
resolver.setServers([ip]); | |
return resolver; | |
}); | |
function check(resolver) { | |
return new Promise(resolve => { | |
resolver.resolve4(name, (err, addresses) => { | |
// c-ares sends NXDOMAIN (the code we care about) as ENOTFOUND, but | |
// we don't want any error to be fatal here either. | |
console.log(Date.now(), resolver.getServers()[0], !err); | |
resolve(); | |
}); | |
}); | |
} | |
function checkAll() { | |
Promise.all(resolvers.map(check)).then(() => setTimeout(checkAll)); | |
} | |
checkAll(); | |
// Do one of these at a time, adjusting the resolves array above accordingly: | |
////// GCP | |
dnsZone.addRecords(dnsZone.record("A", { | |
name: `${name}.`, | |
data: "123.123.123.123", | |
ttl: 60 | |
})); | |
////// AWS | |
route53.changeResourceRecordSets({ | |
ChangeBatch: { | |
Changes: [ | |
{ | |
Action: "CREATE", | |
ResourceRecordSet: { | |
Name: `${name}.`, | |
ResourceRecords: [{ | |
Value: "123.123.123.123" | |
}], | |
TTL: 60, | |
Type: "A" | |
} | |
} | |
] | |
}, | |
HostedZoneId: "<hosted zone ID>" | |
}, (err, data) => { | |
console.log("ADDED RECORD", err); | |
}); | |
console.log(Date.now(), "ADDRECORD"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment