Last active
July 27, 2017 21:59
-
-
Save gambtho/4dc82ffe1fbd94f3fd31a643d19424ec 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
var AWS = require('aws-sdk'); | |
AWS.config.region = 'us-east-1'; | |
function validInstance(instance) { | |
return instance.SecurityGroups[0] && | |
instance.SecurityGroups[0].GroupName === 'ctf_instance' && | |
instance.State.Code == 16 && | |
instance.Tags[0] | |
} | |
function getInstances(data) { | |
return data.Reservations.map(function(reservation) { | |
return reservation.Instances.filter(function(instance) { | |
return validInstance(instance) | |
}).map(function(instance) { | |
return instance.Tags[0].Value + ":" + instance.PrivateIpAddress | |
}) | |
}).filter(function(result) { | |
return result.length > 0 && result !== null | |
}) | |
} | |
exports.handler = function(event, context) { | |
var ec2 = new AWS.EC2(); | |
ec2.describeInstances(function(err, data) { | |
if (err) context.done(err, err.stack); | |
else context.done(null, getInstances(data)) | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment