Created
November 27, 2015 02:52
-
-
Save horike37/db659dffa8e12ae7907d to your computer and use it in GitHub Desktop.
EC2インスタンスを起動させるためのLambdaファンクション
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'); | |
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