Created
October 12, 2015 14:02
-
-
Save bobey/9bc169449e018162e83d to your computer and use it in GitHub Desktop.
Generate a .ssh/config file from your EC2 instances
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
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