Skip to content

Commit 119b943

Browse files
committed
Upgrade aws-sdk from v2 to v3
Add files array property to package.json See issue: purpleteam-labs/purpleteam#81
1 parent 6cc9c19 commit 119b943

File tree

9 files changed

+1496
-136
lines changed

9 files changed

+1496
-136
lines changed

cloud/app-emissary-provisioner/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with purpleteam. If not, see <https://www.gnu.org/licenses/>.
1616

17-
// Doc: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECS.html
18-
const ECS = require('aws-sdk/clients/ecs'); // eslint-disable-line import/no-unresolved
17+
// Doc: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ecs/index.html
18+
const { ECSClient, CreateServiceCommand } = require('@aws-sdk/client-ecs');
1919

2020
const internals = {};
2121

@@ -90,7 +90,7 @@ internals.deployEmissaries = async (dTOItems, {
9090

9191
if (dTOItems.length < 1 || dTOItems.length > 12) throw new Error(`The number of items requested was: ${dTOItems.length}. The supported number of Test Sessions is from 1-12 inclusive.`);
9292

93-
const ecs = new ECS({ region: process.env.AWS_REGION });
93+
const ecsClient = new ECSClient({ region: process.env.AWS_REGION });
9494

9595
const browserCounts = dTOItems.map((cV) => cV.browser).reduce((accumulator, currentValue) => {
9696
accumulator[currentValue] = 1 + (accumulator[currentValue] || 0);
@@ -133,7 +133,7 @@ internals.deployEmissaries = async (dTOItems, {
133133
const splitItemsWithExtras = [...appItemsWithExtras, ...seleniumItemsWithExtras];
134134
console.info(`The value of splitItemsWithExtras is: ${JSON.stringify(splitItemsWithExtras)}`);
135135

136-
const promisedResponses = splitItemsWithExtras.map((cV) => ecs.createService({
136+
const createServiceCommands = splitItemsWithExtras.map((cV) => new CreateServiceCommand({
137137
cluster: customerClusterArn,
138138
serviceName: cV.ecsServiceName,
139139
taskDefinition: cV.taskDefinition,
@@ -145,10 +145,12 @@ internals.deployEmissaries = async (dTOItems, {
145145
// port: 'NUMBER_VALUE',
146146
registryArn: cV.serviceDiscoveryServiceArn
147147
}]
148-
}).promise());
148+
}));
149+
const promisedResponses = createServiceCommands.map((c) => ecsClient.send(c));
150+
149151
try {
150152
const resolved = await promiseAllTimeout(promisedResponses, s2ProvisioningTimeout);
151-
console.info(`The data objects returned from calling ecs.createService were: ${JSON.stringify(resolved)}`);
153+
console.info(`The data objects returned from calling ECS createServiceCommand were: ${JSON.stringify(resolved)}`);
152154
resolved.every((e) => !e) && (result.error = 'Timeout exceeded: App Emissary container(s) took too long to start. Although they timed out, they may have still started.');
153155
} catch (e) {
154156
console.error('Exception occurred, details follow:');

cloud/app-emissary-provisioner/package-lock.json

Lines changed: 733 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/app-emissary-provisioner/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
"repository": "https://github.com/purpleteam-labs/purpleteam-lambda",
77
"author": "Kim Carter",
88
"license": "AGPL-3.0-only",
9-
"dependencies": {},
9+
"dependencies": {
10+
"@aws-sdk/client-ecs": "^3.18.0"
11+
},
1012
"scripts": {
1113
"deps": "npm-check",
1214
"update:deps": "npm-check -u"
1315
},
1416
"devDependencies": {
1517
"npm-check": "^5.9.2"
16-
}
18+
},
19+
"files": []
1720
}

cloud/s2-deprovisioner/index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with purpleteam. If not, see <https://www.gnu.org/licenses/>.
1616

17-
// Doc: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ECS.html
18-
const ECS = require('aws-sdk/clients/ecs'); // eslint-disable-line import/no-unresolved
17+
// Doc: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ecs/index.html
18+
const { ECSClient, DeleteServiceCommand } = require('@aws-sdk/client-ecs');
1919

2020
const internals = {};
2121

@@ -69,16 +69,11 @@ internals.promiseAllTimeout = async (promises, timeout, resolvePartial = true) =
6969

7070
internals.downContainers = async (ecsServiceNames, { clientContext: { Custom: { /* customer, */ customerClusterArn } } }) => {
7171
const { promiseAllTimeout, s2ProvisioningTimeout } = internals;
72-
const ecs = new ECS({ region: process.env.AWS_REGION });
73-
74-
const promisedResponses = ecsServiceNames.map((sN) => ecs.deleteService({
75-
cluster: customerClusterArn,
76-
service: sN,
77-
force: true
78-
}).promise());
72+
const ecsClient = new ECSClient({ region: process.env.AWS_REGION });
73+
const deleteServiceCommands = ecsServiceNames.map((sN) => new DeleteServiceCommand({ cluster: customerClusterArn, service: sN, force: true }));
74+
const promisedResponses = deleteServiceCommands.map((c) => ecsClient.send(c));
7975
const resolved = await promiseAllTimeout(promisedResponses, s2ProvisioningTimeout);
80-
81-
console.info(`These are the values returned from ecs.deleteService: ${JSON.stringify(resolved)}`);
76+
console.info(`These are the values returned from the ECS deleteServiceCommand: ${JSON.stringify(resolved)}`);
8277

8378
return resolved.every((e) => !!e)
8479
? { item: `Stage Two ECS services (${JSON.stringify(ecsServiceNames)}) have been brought down.` }

0 commit comments

Comments
 (0)