Skip to content

Instantly share code, notes, and snippets.

@nulltask
Last active December 2, 2018 21:45
Show Gist options
  • Select an option

  • Save nulltask/1d1cfa26bf8ba760177e to your computer and use it in GitHub Desktop.

Select an option

Save nulltask/1d1cfa26bf8ba760177e to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk');
AWS.config.update({
logger: process.stdout,
region: 'ap-northeast-1'
});
var r53 = new AWS.Route53();
var params = {
HostedZoneId: 'hostedzone/XXXXXXXXXXXXXX',
ChangeBatch: {
Changes: [
{
Action: 'UPSERT',
ResourceRecordSet: {
Name: 'foobar.io.example.org',
Type: 'CNAME',
ResourceRecords: [
{ Value: 'ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com' }
]
},
}
]
}
};
r53.changeResourceRecordSets(params, function(err, res) {
console.log(err, res);
});
var Serf = require('node-serf');
var AWS = require('aws-sdk');
AWS.config.update({
logger: process.stdout,
region: 'ap-northeast-1'
});
var serf = Serf.connect({ port: 7373 });
var ec2 = new AWS.EC2();
var elb = new AWS.ELB();
elb.describeInstanceHealth({ LoadBalancerName: 'your-balancer-name' }, function(err, res) {
if (err) {
return console.error(err.name, err.stack);
}
var instanceIds = res.InstanceStates.map(function(item) {
return item.InstanceId;
});
ec2.describeInstances({ InstanceIds: instanceIds }, function(err, res) {
if (err) {
return console.error(err.name, err.stack);
}
var privateIpAddrs = res.Reservations.map(function(item) {
return item.Instances.map(function(item) {
return item.PrivateIpAddress + ':7946';
});
});
serf.join({ Existing: [].concat.apply([], privateIpAddrs) });
});
});
var sha1 = require('sha1');
var Serf = require('node-serf');
var serf = Serf.connect({ port: 7373 });
serf.on('connect', function() {
serf.members(function(members) {
var hosts = members.Members.map(function(item) {
return sha1(item.Name).slice(0, 10) + '.io.example.org';
});
console.log(hosts);
serf.destroy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment