Created
June 25, 2016 07:06
-
-
Save pahud/7db5aabc2a0f1843afd417dc0b380bc4 to your computer and use it in GitHub Desktop.
ECS task runner with 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') | |
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
Works very well, thank you :) 👍