Skip to content

Instantly share code, notes, and snippets.

@horike37
Created November 27, 2015 02:52
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 horike37/db659dffa8e12ae7907d to your computer and use it in GitHub Desktop.
Save horike37/db659dffa8e12ae7907d to your computer and use it in GitHub Desktop.
EC2インスタンスを起動させるためのLambdaファンクション
var AWS = require('aws-sdk');
function startInstance(instance_id, context) {
var ec2 = new AWS.EC2();
var params = {
InstanceIds: [
instance_id
]
};
ec2.startInstances(params, function(err, data) {
if (err){ console.log(err, err.stack);
} else {
ec2.waitFor('instanceRunning', params, function(err, data) {
if (err) console.log(err, err.stack);
else context.done(null, data);
});
}
});
}
exports.handler = function(event, context) {
startInstance(event.instance_id, context);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment