Skip to content

Instantly share code, notes, and snippets.

@bobey
Created October 12, 2015 14:02
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 bobey/9bc169449e018162e83d to your computer and use it in GitHub Desktop.
Save bobey/9bc169449e018162e83d to your computer and use it in GitHub Desktop.
Generate a .ssh/config file from your EC2 instances
var AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
var ec2 = new AWS.EC2();
ec2.describeInstances({}, function(err, data) {
data.Reservations.forEach(function(reservation) {
reservation.Instances.forEach(function(instance) {
var nameTag = instance.Tags.filter(function(tag) {
return 'Name' === tag.Key;
});
var name = nameTag[0].Value.toLowerCase().replace('aws-', ''),
ipAddress = instance.PublicIpAddress;
if (!name || !ipAddress) {
return;
}
console.log('Host ' + name);
console.log(' Hostname ' + ipAddress);
console.log(' Port 22');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment