Skip to content

Commit 3e81154

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

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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";
3+
import { ServiceException } from "@smithy/smithy-client";
4+
/* We really should be migrating to v3, but for now use v2 */
45
import { getTestCaseTaskDefinition } from "../utils/config-utils.js";
56
import { PromiseResult } from "aws-sdk/lib/request";
6-
process.env.AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE = '1';
77
import * as Constants from "../constants.js"
88

99
let ecsTestCaseTaskQueue: Array<IEcsTestTask> = [];
@@ -61,22 +61,21 @@ async function processEcsTestTaskQueue() {
6161
async function startECSTask(task: IEcsTestTask) {
6262
const testCase = task.testCase;
6363

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

7069
// Create fargate cluster if it doesn't already exist
71-
const clusters = await ecs.listClusters().promise();
70+
const clusters = await ecs.listClusters();
7271
if (!clusters.clusterArns.some(c => c.endsWith(`/${testCase.config.cluster}`))) {
7372
await ecs.createCluster({
7473
settings: [{
7574
name: "containerInsights",
7675
value: "enabled"
7776
}],
7877
clusterName: testCase.config.cluster
79-
}).promise();
78+
});
8079
console.log(`🍇 Created cluster: ${testCase.config.cluster}\n`)
8180
await sleep(2000); /* Wait for the container to be ready to accept new tasks */
8281
}
@@ -87,7 +86,7 @@ async function startECSTask(task: IEcsTestTask) {
8786
// Register task definition
8887
let taskDefinitionArn;
8988
try {
90-
taskDefinitionArn = (await ecs.registerTaskDefinition(taskDefinition).promise()).taskDefinition!.taskDefinitionArn;
89+
taskDefinitionArn = (await ecs.registerTaskDefinition(taskDefinition)).taskDefinition!.taskDefinitionArn;
9190
}
9291
catch (err) {
9392
console.error(`Error registering task definition: ${err}`);
@@ -133,11 +132,10 @@ function ecsTaskReturn(ecsTestTask: IEcsTestTask) {
133132
async function validateAndRetryECSTask(ecsTestTask: IEcsTestTask) {
134133
const testCase = ecsTestTask.testCase;
135134

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

142140
const {
143141
currentTasks,
@@ -182,11 +180,10 @@ async function validateAndRetryECSTask(ecsTestTask: IEcsTestTask) {
182180
async function outOfRetriesECSTask(ecsTestTask: IEcsTestTask) {
183181
const testCase = ecsTestTask.testCase;
184182

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

191188
const {
192189
runningTasksCount,
@@ -212,11 +209,11 @@ async function outOfRetriesECSTask(ecsTestTask: IEcsTestTask) {
212209
}
213210

214211

215-
async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: AWS.ECS, taskDefinitionArn: string): Promise<string[]> {
212+
async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: ECS, taskDefinitionArn: string): Promise<string[]> {
216213
let launchedTasks = [];
217214
while (launchedTasks.length < taskCount) {
218215
const launchCount = Math.min(10, taskCount - launchedTasks.length);
219-
let result: PromiseResult<AWS.ECS.RunTaskResponse, AWS.AWSError>;
216+
let result: PromiseResult<RunTaskCommandOutput, ServiceException>;
220217
try {
221218
result = await ecs.runTask({
222219
enableExecuteCommand: true,
@@ -231,7 +228,7 @@ async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: AWS.E
231228
securityGroups: testCase.config.taskVpcSecurityGroups,
232229
}
233230
}
234-
}).promise();
231+
});
235232
}
236233
catch (err) {
237234
console.error(`Error launching task: ${err}`);
@@ -254,8 +251,10 @@ async function launchECSTasks(testCase: ITestCase, taskCount: number, ecs: AWS.E
254251
return launchedTasks;
255252
}
256253

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();
254+
async function validateECSTestTask(ecs: ECS, ecsTestTask: IEcsTestTask) {
255+
const currentTasks = await ecs.describeTasks(
256+
{cluster: ecsTestTask.testCase.config.cluster, tasks: ecsTestTask.executionRecord.taskArns},
257+
);
259258
const startingTasks = currentTasks.tasks
260259
.filter(t => (t.taskDefinitionArn === ecsTestTask.taskDefinitionArn) &&
261260
(t.lastStatus === "PROVISIONING" || t.lastStatus === "PENDING" || t.lastStatus === "ACTIVATING"))

clients/s3-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import AWS from 'aws-sdk';
1+
import { S3 } from "@aws-sdk/client-s3";
22
import { IClient } from "../core/ext-types.js"
33
import { IExecutionResult } from "../core/pipeline-types.js";
44

55
const environmentClient: IClient = {
66
name: "s3",
77
makeCommandGenerator: (async function*() {
88

9-
const s3 = new AWS.S3();
9+
const s3 = new S3();
1010

1111
const bucket = process.env.CLIENT_S3_BUCKET || 'firelens-datajet';
1212
const file = process.env.CLIENT_S3_FILE || 'firelens-datajet.json';
@@ -15,7 +15,7 @@ const environmentClient: IClient = {
1515
const s3Response = await s3.getObject({
1616
Bucket: bucket,
1717
Key: file
18-
}).promise();
18+
});
1919

2020
const config = JSON.parse(s3Response.Body.toString());
2121

generators/s3-generator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import AWS from 'aws-sdk';
7+
import { S3 } from "@aws-sdk/client-s3";
88
import { IBatchGenerator, ILogData } from "../core/ext-types.js"
99
import fs from 'fs';
1010
import readline from 'readline';
@@ -39,7 +39,7 @@ const s3Generator: IBatchGenerator = {
3939
defaultConfig: defaultConfig,
4040
createConfiguredGenerator: function (config: IGeneratorConfig) {
4141

42-
const s3 = new AWS.S3();
42+
const s3 = new S3();
4343

4444
const bucket = config.bucket
4545
const file = config.file;
@@ -56,7 +56,7 @@ const s3Generator: IBatchGenerator = {
5656
const s3Response = await s3.getObject({
5757
Bucket: bucket,
5858
Key: file
59-
}).promise();
59+
});
6060

6161
s3Logs = (s3Response?.Body?.toString() ?? "").split("\n");
6262
}
@@ -101,7 +101,7 @@ const s3Generator: IBatchGenerator = {
101101
hasLooped = true;
102102
}
103103
})()),
104-
}
104+
};
105105
}
106106

107107
};

0 commit comments

Comments
 (0)