Skip to content

Instantly share code, notes, and snippets.

@pahud
Created June 25, 2016 07:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pahud/7db5aabc2a0f1843afd417dc0b380bc4 to your computer and use it in GitHub Desktop.
Save pahud/7db5aabc2a0f1843afd417dc0b380bc4 to your computer and use it in GitHub Desktop.
ECS task runner with Lambda
var AWS = require('aws-sdk')
var ecs = new AWS.ECS();
exports.handler = (events, context) => {
// CLI example:
// aws --region ap-northeast-1 ecs run-task --task-definition my_task_def
/* input event payload sample:
{
"ecs_task_def": "my_task_def",
"region": "us-west-2",
"cluster": "default",
"count": 1
}
*/
console.log(events)
var ecs_task_def = events.ecs_task_def || 'undefined'
var exec_region = events.region || 'ap-northeast-1'
var cluster = events.cluster || 'default'
var count = events.count || 1
console.log(ecs_task_def, exec_region)
var params = {
taskDefinition: ecs_task_def,
cluster: cluster,
count: count
}
ecs.runTask(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
context.done(err, data)
})
}
@Nicklas2751
Copy link

Works very well, thank you :) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment