Skip to content

Instantly share code, notes, and snippets.

@gregtaylor99
Forked from pahud/ecs_task_runner.js
Created March 23, 2018 01:35
Show Gist options
  • Save gregtaylor99/251b664f34817bda281f4d31db32d90e to your computer and use it in GitHub Desktop.
Save gregtaylor99/251b664f34817bda281f4d31db32d90e 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)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment