Skip to content

Commit 73943ca

Browse files
feat(AWS): Upgrade AWS SDK to v3 (LLC-1464) (#863)
BREAKING CHANGE: Upgraded AWS SDK to v3 and changed app config shape
1 parent 930a08c commit 73943ca

File tree

155 files changed

+1672
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+1672
-505
lines changed

@types/string-to-stream/index.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
"npm": ">3.0.0"
4040
},
4141
"dependencies": {
42+
"@aws-sdk/client-s3": "^3.100.0",
43+
"@aws-sdk/lib-storage": "^3.100.0",
4244
"@azure/storage-blob": "^10.3.0",
4345
"@google-cloud/storage": "^5.8.1",
4446
"@learninglocker/xapi-validation": "^2.1.10",
4547
"accept-language-parser": "^1.5.0",
4648
"atob": "^2.0.3",
47-
"aws-sdk": "^2.205.0",
4849
"bluebird": "3.7.2",
4950
"boolean": "^0.2.0",
5051
"btoa": "^1.1.2",
@@ -55,7 +56,7 @@
5556
"http-status-codes": "^2.0.0",
5657
"install": "^0.13.0",
5758
"ioredis": "^4.14.0",
58-
"jscommons": "^3.0.2",
59+
"jscommons": "^4.0.0",
5960
"jsonwebtoken": "^8.5.1",
6061
"lodash": "^4.17.4",
6162
"mime-types": "2.1.35",
@@ -70,7 +71,6 @@
7071
"sha1": "^1.1.1",
7172
"source-map-support": "^0.5.0",
7273
"stream-to-string": "^1.2.0",
73-
"string-to-stream": "^2.0.0",
7474
"uuid": "^8.0.0"
7575
},
7676
"devDependencies": {
@@ -89,7 +89,7 @@
8989
"@types/mime-types": "2.1.1",
9090
"@types/mocha": "8.2.3",
9191
"@types/mongodb": "3.6.18",
92-
"@types/node": "9.6.61",
92+
"@types/node": "^14.18.18",
9393
"@types/node-fetch": "2.5.8",
9494
"@types/object-hash": "1.3.4",
9595
"@types/redis": "2.8.32",

src/apps/AppConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { S3 } from 'aws-sdk';
1+
import { S3ClientConfig } from '@aws-sdk/client-s3';
22
import { Redis } from 'ioredis';
33
import Tracker from 'jscommons/dist/tracker/Tracker';
44
import { Db } from 'mongodb';
@@ -34,7 +34,7 @@ export default interface AppConfig {
3434
readonly storageDir: string;
3535
};
3636
readonly s3: {
37-
readonly awsConfig: S3.ClientConfiguration;
37+
readonly awsConfig: S3ClientConfig;
3838
readonly bucketName: string;
3939
};
4040
readonly mongo: {

src/apps/activities/AppConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import S3 from 'aws-sdk/clients/s3';
1+
import { S3ClientConfig } from '@aws-sdk/client-s3';
22
import Tracker from 'jscommons/dist/tracker/Tracker';
33
import { Db } from 'mongodb';
44
import { LoggerInstance } from 'winston';
@@ -33,7 +33,7 @@ export default interface AppConfig {
3333
readonly storageDir: string;
3434
};
3535
readonly s3: {
36-
readonly awsConfig: S3.ClientConfiguration;
36+
readonly awsConfig: S3ClientConfig;
3737
readonly bucketName: string;
3838
};
3939
readonly mongo: {

src/apps/activities/expressPresenter/utils/alternateProfileRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Request, Response } from 'express';
22
import { get, mapKeys } from 'lodash';
33
import { parse as parseQueryString } from 'query-string';
44
import streamToString from 'stream-to-string';
5-
import stringToStream from 'string-to-stream';
5+
import { stringToStream } from '../../../../utils/stringToStream';
66
import InvalidMethod from '../../errors/InvalidMethod';
77
import Config from '../Config';
88
import deleteProfileWithService from './deleteProfileWithService';

src/apps/activities/mongoAuthRepo/tests/getClient.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('getClient from mongo client', () => {
6363
await db.collection('lrs').insertOne(TEST_STORE);
6464
await db.collection('client').insertOne(TEST_CLIENT);
6565
const result = await authRepo.getClient({ authToken: TEST_TOKEN });
66-
assert.equal(result.client._id, TEST_CLIENT._id);
66+
assert.strictEqual(result.client._id, TEST_CLIENT._id.toString());
6767
});
6868

6969
it('should error when getting a untrusted client', async () => {
@@ -130,7 +130,7 @@ describe('getClient from mongo client', () => {
130130
await db.collection('client').insertOne(TEST_CLIENT);
131131
await db.collection('oAuthTokens').insertOne(TEST_OAUTH_TOKEN);
132132
const result = await authRepo.getClient({ authToken: `Bearer ${TEST_ACCESS_TOKEN}` });
133-
assert.equal(result.client._id, TEST_CLIENT._id);
133+
assert.strictEqual(result.client._id, TEST_CLIENT._id.toString());
134134
});
135135

136136
it('should error when access_token is not found in collection', async () => {

src/apps/activities/repo/storage/FactoryConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { S3 } from 'aws-sdk';
1+
import { S3ClientConfig } from '@aws-sdk/client-s3';
22

33
export default interface FactoryConfig {
44
readonly factoryName: string;
@@ -18,7 +18,7 @@ export default interface FactoryConfig {
1818
readonly storageDir: string;
1919
};
2020
readonly s3: {
21-
readonly awsConfig: S3.ClientConfiguration;
21+
readonly awsConfig: S3ClientConfig;
2222
readonly bucketName: string;
2323
readonly subFolder: string;
2424
};

src/apps/activities/repo/storage/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ContainerURL, ServiceURL, SharedKeyCredential, StorageURL } from '@azure/storage-blob';
22
import { Storage } from '@google-cloud/storage';
3-
import S3 from 'aws-sdk/clients/s3';
3+
import { S3Client } from '@aws-sdk/client-s3';
44
import azureStorageRepo from '../../azureStorageRepo';
55
import googleStorageRepo from '../../googleStorageRepo';
66
import localStorageRepo from '../../localStorageRepo';
@@ -13,7 +13,7 @@ export default (factoryConfig: FactoryConfig): Repo => {
1313
case 's3':
1414
return s3StorageRepo({
1515
bucketName: factoryConfig.s3.bucketName,
16-
client: new S3(factoryConfig.s3.awsConfig) as any,
16+
client: new S3Client(factoryConfig.s3.awsConfig),
1717
subFolder: factoryConfig.s3.subFolder,
1818
});
1919
case 'google':

src/apps/activities/repoFactory/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ContainerURL, ServiceURL, SharedKeyCredential, StorageURL } from '@azure/storage-blob';
22
import { Storage } from '@google-cloud/storage';
3-
import S3 from 'aws-sdk/clients/s3';
3+
import { S3Client } from '@aws-sdk/client-s3';
44
import connectToDb from 'jscommons/dist/mongoRepo/utils/connectToDb';
55
import config from '../../../config';
66
import logger from '../../../logger';
@@ -54,7 +54,7 @@ const getStorageRepo = (): StorageRepo => {
5454
case 's3':
5555
return s3StorageRepo({
5656
bucketName: config.s3StorageRepo.bucketName,
57-
client: new S3(config.s3StorageRepo.awsConfig) as any,
57+
client: new S3Client(config.s3StorageRepo.awsConfig),
5858
subFolder: config.storageSubFolders.activities,
5959
});
6060
case 'google':
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
12
import DeleteProfileContentOptions from '../repoFactory/options/DeleteProfileContentOptions';
23
import getStorageDir from '../utils/getStorageDir';
34
import Config from './Config';
@@ -6,11 +7,13 @@ export default (config: Config) => {
67
return async (opts: DeleteProfileContentOptions): Promise<void> => {
78
const profileDir = getStorageDir({ subfolder: config.subFolder, lrs_id: opts.lrs_id });
89
const filePath = `${profileDir}/${opts.key}`;
9-
await config.client
10-
.deleteObject({
11-
Bucket: config.bucketName,
12-
Key: filePath,
13-
})
14-
.promise();
10+
11+
const deletionCommand = new DeleteObjectCommand({
12+
Bucket: config.bucketName,
13+
Key: filePath,
14+
});
15+
await config.client.send(deletionCommand);
16+
17+
return;
1518
};
1619
};

0 commit comments

Comments
 (0)