Skip to content

Instantly share code, notes, and snippets.

@andreigec
Created October 5, 2019 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreigec/ce9a1793c6122133dbf0e0f0476b5dd0 to your computer and use it in GitHub Desktop.
Save andreigec/ce9a1793c6122133dbf0e0f0476b5dd0 to your computer and use it in GitHub Desktop.
var AWS = require("aws-sdk")
var accessKeyId = "AAA"
var secretAccessKey = "BBB"
var route53 = {}
var hz = "XXX"
var name = "ZZZ"
var update = async (ip, hz, name) => {
return new Promise((res, rej) => {
var params = {
ChangeBatch: {
Changes: [
{
Action: "UPSERT",
ResourceRecordSet: {
Name: name,
ResourceRecords: [
{ Value: ip }
],
TTL: 60,
Type: "A"
}
}
],
Comment: "auto ip update"
},
HostedZoneId: hz
}
route53.changeResourceRecordSets(params, (err, data) => {
console.log("err=", err)
console.log("Data=", data)
if (err) {
rej(err)
} else {
res(data)
}
})
})
}
var main = async ([, , ip]) => {
var creds = {
accessKeyId,
secretAccessKey
}
AWS.config.credentials = new AWS.Credentials(creds);
route53 = new AWS.Route53(creds);
console.log("ip=", ip)
await update(ip, hz, name)
}
main(process.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment