ec2-each is a node package for iterating EC2 instances and doing things.
$ npm install ec2-each
var logReservationIds = function(callback) {
var config = {
accessKeyId: "AAAABBBBCCCCDDDDEEEE",
secretAccessKey: "aaaa2222bbbb3333cccc4444dddd5555eeeefff",
awsAccountId: 123456789012,
region: "eu-west-1"
};
var logReservationId = function(item, state, callback) {
console.log(item.reservationId);
callback(null);
};
var ec2 = new each.EC2(config);
ec2.running(function(err, instances) {
ec2.each(instances, logReservationId, null, callback);
});
};
Returns a set of all EC2 instances (irrespective of status) that can be passed into each. The supplied awssum filters will be applied.
Returns a set of all running EC2 instances that can be passed into each.
Returns true if instances is not empty
Calls the action function once per EC2 instance passed in. The instances must be in the format as returned by all, running or an awssum DescribeInstances call.
The action could, for example, make an ssh call to the EC2 instance.
The state is passed to every action.
The callback is passed an error if any of the actions fail and the callback data contains an array of action results.
All actions are called in parallel.
Pair programmed by Roy Lines and James Bloomer.