+// AWS SDK object instance
+var AWS = require('aws-sdk');
+// The names of the EC2 instances that we wish to stop.
+// Servers need to have a "Tag" with the name of "Name" and the value is as
+// included in the list below.
+var instanceNames = ['YourServerName1', 'YourServerName2', 'YourServerName3'];
+// node.js event handler declaration
+exports.handler = function(event, context) {
+ // AWS EC2 object instance
+ var ec2 = new AWS.EC2({region: 'eu-west-1'});
+ var instanceIds = { InstanceIds: []};
+ ec2.describeInstances(params, function (err, data) {
+ if (err) return console.error(err.message);
+ for(var i = 0; i < result.Reservations.length; ++i) {
+ for(var j = 0; j < result.Reservations[i].Instances.length; ++j) {
+ instanceIds.InstanceIds.push(result.Reservations[i].Instances[j].InstanceId);
+ console.log(JSON.stringify(instanceIds));
+ // call AWS API to start list of instances
+ ec2.startInstances(instanceIds, function (err, data) {
+ // log failed with stack trace
+ console.log(err, err.stack);
+ console.log(JSON.stringify(data));
+ context.done(err,data);