This repository was archived by the owner on Aug 26, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtaskrunner.js
More file actions
78 lines (65 loc) · 2.21 KB
/
Copy pathtaskrunner.js
File metadata and controls
78 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
const { ECS } = require("@aws-sdk/client-ecs");
const region = process.env.AWS_DEFAULT_REGION || 'us-east-1';
module.exports = {
makeCmd: function (options) {
return [
'sh', '-c',
`sh -c "${options.cmd}"; EXITCODE=$?; echo "TASK FINISHED: $(echo -n ${options.endOfStreamIdentifier} | base64), EXITCODE: $EXITCODE"`
];
},
run: function (options, cb) {
const ecs = new ECS({ region: region });
const params = {
cluster: options.clusterArn,
taskDefinition: options.taskDefinitionArn,
launchType: options.launchType,
overrides: {
containerOverrides: [
{
name: options.containerName,
command: this.makeCmd(options)
}
]
}
};
if (options.startedBy !== undefined) {
params.startedBy = options.startedBy;
}
if (options.env !== undefined) {
params.overrides.containerOverrides[0].environment = options.env;
}
// Since yargs' boolean argument type will always be true or false, we can't distinguish between assignPublicIp not
// being set and it being false. Therefore we'll always set it, as long as we have an awsvpcConfiguration block.
if (options.subnets !== undefined || options.securityGroups !== undefined || options.assignPublicIp === true) {
params.networkConfiguration = {
awsvpcConfiguration: {
assignPublicIp: options.assignPublicIp ? 'ENABLED' : 'DISABLED'
}
};
}
if (options.subnets !== undefined) {
params.networkConfiguration.awsvpcConfiguration.subnets = options.subnets;
}
if (options.securityGroups !== undefined) {
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));
},
stop: function (options, cb) {
const ecs = new ECS({ region: region });
const params = {
cluster: options.clusterArn,
task: options.taskId,
reason: options.reason
};
ecs.stopTask(params)
.then(data => cb(null, data))
.catch(err => cb(err, null));
}
}