Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Array of security-groups.
The AWS region used when accessing ECS and CloudWatch. If nothing is provided falls back to `us-east-1`.
The `AWS_DEFAULT_REGION` environment variable has precendence over this setting.

#### tag
This option is a key/value pair defined as `key=value` and can be repeated multiple times. Each pair is passed as a tag of the launched task, where `key` is the name of the tag and `value` is it's value.

### Example Module Usage

```
Expand Down
13 changes: 12 additions & 1 deletion bin/ecs-task-runner
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ const argv = yargs
describe: 'Security groups network configuration (awsvpc configuration)',
type: 'array'
})
.option('tag', {
array: true,
describe: 'key=value Pass tag to add to the task',
coerce: opts => {
return opts.map(item => {
let pieces = item.split('=');
return { key: pieces[0], value: pieces[1] };
})
}
})
.help()
.wrap(yargs.terminalWidth())
.argv;
Expand All @@ -76,7 +86,8 @@ const options = {
launchType: argv.launchType,
assignPublicIp: argv.assignPublicIp,
subnets: argv.subnets,
securityGroups: argv.securityGroups
securityGroups: argv.securityGroups,
tags: argv.tag
};

ecsTaskRunner(options, function (err, stream) {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ module.exports = function (options, cb) {
launchType: options.launchType,
assignPublicIp: options.assignPublicIp,
subnets: options.subnets,
securityGroups: options.securityGroups
securityGroups: options.securityGroups,
tags: options.tags
};

taskRunner.runPromisified = util.promisify(taskRunner.run);
Expand Down
4 changes: 4 additions & 0 deletions lib/taskrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module.exports = {
params.networkConfiguration.awsvpcConfiguration.securityGroups = options.securityGroups;
}

if (options.tags !== undefined) {
params.tags = options.tags
}

ecs.runTask(params)
.then(data => cb(null, data))
.catch(err => cb(err, null));
Expand Down
30 changes: 30 additions & 0 deletions test/taskrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ describe('TaskRunner', function () {
done();
});
});

it('should make a call to AWS.ECS with correct arguments including tags', function (done) {
const options = {
clusterArn: 'cluster.arn',
taskDefinitionArn: 'task-definition.arn',
containerName: 'container name',
cmd: 'mycommand --arg "Woot"',
endOfStreamIdentifier: '1234',
startedBy: 'Bugs Bunny',
tags: [{ key: 'task', value: 'cleanup' }, { key: 'database', value: 'abc' }]
};

ecsMock.on(RunTaskCommand).callsFake((params) => {
expect(params.cluster).to.equal(options.clusterArn);
expect(params.taskDefinition).to.equal(options.taskDefinitionArn);
expect(params.startedBy).to.equal(options.startedBy);
expect(params.tags).to.equal(options.tags);

const cmdOverride = params.overrides.containerOverrides[0];
expect(cmdOverride.name).to.equal(options.containerName);
expect(cmdOverride.command).to.eql(taskRunner.makeCmd(options));

return Promise.resolve({ taskArn: "Yo" });
});

taskRunner.run(options, function (err, _task) {
expect(err).to.equal(null);
done();
});
});
});

describe('#stop', function () {
Expand Down