Skip to content

Commit 5867d84

Browse files
committed
chore: migrate AWS SDK for JavaScript v2 APIs to v3
1 parent 37fea75 commit 5867d84

File tree

7 files changed

+6221
-4973
lines changed

7 files changed

+6221
-4973
lines changed

apps/firelens-stability/lib/cloud/ecs.ts

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { getJsonFromFile, sleep } from "../utils/utils.js";
2-
import * as ECS from "@aws-sdk/client-ecs";
3-
import AWS from 'aws-sdk'; /* We really should be migrating to v3, but for now use v2 */
2+
import { ECS, RunTaskCommandOutput } from "@aws-sdk/client-ecs";
43
import { getTestCaseTaskDefinition } from "../utils/config-utils.js";
5-
import { PromiseResult } from "aws-sdk/lib/request";
6-
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
74
import * as Constants from "../constants.js"
85

96
let ecsTestCaseTaskQueue: Array<IEcsTestTask> = [];
@@ -61,22 +58,21 @@ async function processEcsTestTaskQueue() {
6158
async function startECSTask(task: IEcsTestTask) {
6259
const testCase = task.testCase;
6360

64-
// Set the region name
65-
AWS.config.update({ region: testCase.config.region });
66-
6761
// Create an ECS client
68-
const ecs = new AWS.ECS();
62+
const ecs = new ECS({
63+
region: testCase.config.region,
64+
});
6965

7066
// Create fargate cluster if it doesn't already exist
71-
const clusters = await ecs.listClusters().promise();
67+
const clusters = await ecs.listClusters();
7268
if (!clusters.clusterArns.some(c => c.endsWith(`/${testCase.config.cluster}`))) {
7369
await ecs.createCluster({
7470
settings: [{
7571
name: "containerInsights",
7672
value: "enabled"
7773
}],
7874
clusterName: testCase.config.cluster
79-
}).promise();
75+
});
8076
console.log(`🍇 Created cluster: ${testCase.config.cluster}\n`)
8177
await sleep(2000); /* Wait for the container to be ready to accept new tasks */
8278
}
@@ -85,9 +81,9 @@ async function startECSTask(task: IEcsTestTask) {
8581
const taskDefinition = await getTestCaseTaskDefinition(testCase);
8682

8783
// Register task definition
88-
let taskDefinitionArn;
84+
let taskDefinitionArn: string;
8985
try {
90-
taskDefinitionArn = (await ecs.registerTaskDefinition(taskDefinition).promise()).taskDefinition!.taskDefinitionArn;
86+
taskDefinitionArn = (await ecs.registerTaskDefinition(taskDefinition)).taskDefinition!.taskDefinitionArn;
9187
}
9288
catch (err) {
9389
console.error(`Error registering task definition: ${err}`);
@@ -133,11 +129,10 @@ function ecsTaskReturn(ecsTestTask: IEcsTestTask) {
133129
async function validateAndRetryECSTask(ecsTestTask: IEcsTestTask) {
134130
const testCase = ecsTestTask.testCase;
135131

136-
// Set the region name
137-
AWS.config.update({ region: ecsTestTask.testCase.config.region });
138-
139132
// Create an ECS client
140-
const ecs = new AWS.ECS();
133+
const ecs = new ECS({
134+
region: testCase.config.region,
135+
});
141136

142137
const {
143138
currentTasks,
@@ -182,11 +177,10 @@ async function validateAndRetryECSTask(ecsTestTask: IEcsTestTask) {
182177
async function outOfRetriesECSTask(ecsTestTask: IEcsTestTask) {
183178
const testCase = ecsTestTask.testCase;
184179

185-
// Set the region name
186-
AWS.config.update({ region: ecsTestTask.testCase.config.region });
187-
188180
// Create an ECS client
189-
const ecs = new AWS.ECS();
181+
const ecs = new ECS({
182+
region: testCase.config.region,
183+
});
190184

191185
const {
192186
runningTasksCount,
@@ -212,26 +206,26 @@ async function outOfRetriesECSTask(ecsTestTask: IEcsTestTask) {
212206
}
213207

214208

215-
async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: AWS.ECS, taskDefinitionArn: string): Promise<string[]> {
209+
async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: ECS, taskDefinitionArn: string): Promise<string[]> {
216210
let launchedTasks = [];
217211
while (launchedTasks.length < taskCount) {
218212
const launchCount = Math.min(10, taskCount - launchedTasks.length);
219-
let result: PromiseResult<AWS.ECS.RunTaskResponse, AWS.AWSError>;
213+
let result: RunTaskCommandOutput;
220214
try {
221215
result = await ecs.runTask({
222-
enableExecuteCommand: true,
223-
cluster: testCase.config.cluster,
224-
taskDefinition: taskDefinitionArn!,
225-
count: launchCount,
226-
launchType: "FARGATE",
227-
networkConfiguration: {
228-
awsvpcConfiguration: {
229-
subnets: testCase.config.taskVpcSubnets,
230-
assignPublicIp: "DISABLED",
231-
securityGroups: testCase.config.taskVpcSecurityGroups,
216+
enableExecuteCommand: true,
217+
cluster: testCase.config.cluster,
218+
taskDefinition: taskDefinitionArn!,
219+
count: launchCount,
220+
launchType: "FARGATE",
221+
networkConfiguration: {
222+
awsvpcConfiguration: {
223+
subnets: testCase.config.taskVpcSubnets,
224+
assignPublicIp: "DISABLED",
225+
securityGroups: testCase.config.taskVpcSecurityGroups,
226+
}
232227
}
233-
}
234-
}).promise();
228+
});
235229
}
236230
catch (err) {
237231
console.error(`Error launching task: ${err}`);
@@ -254,8 +248,10 @@ async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: AWS.E
254248
return launchedTasks;
255249
}
256250

257-
async function validateECSTestTask(ecs: AWS.ECS, ecsTestTask: IEcsTestTask) {
258-
const currentTasks = await ecs.describeTasks({cluster: ecsTestTask.testCase.config.cluster, tasks: ecsTestTask.executionRecord.taskArns}).promise();
251+
async function validateECSTestTask(ecs: ECS, ecsTestTask: IEcsTestTask) {
252+
const currentTasks = await ecs.describeTasks(
253+
{cluster: ecsTestTask.testCase.config.cluster, tasks: ecsTestTask.executionRecord.taskArns},
254+
);
259255
const startingTasks = currentTasks.tasks
260256
.filter(t => (t.taskDefinitionArn === ecsTestTask.taskDefinitionArn) &&
261257
(t.lastStatus === "PROVISIONING" || t.lastStatus === "PENDING" || t.lastStatus === "ACTIVATING"))

0 commit comments

Comments
 (0)