Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Feb 6, 2017

Works very well, thank you :) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.