Skip to content

Commit 999b27a

Browse files
committed
fix(scripts): make aws command work with new sdk
closes AUTH-979
1 parent 7e3453d commit 999b27a

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

scripts/deploy/lib/copyObject.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const mime = require('mime')
4+
const { CopyObjectCommand } = require('@aws-sdk/client-s3')
45

56
// TODO(mc, 2019-07-16): optimize cache values
67
const getCopyParams = obj => ({
@@ -12,7 +13,7 @@ const getCopyParams = obj => ({
1213
/**
1314
* Copy an object to an S3 bucket
1415
*
15-
* @param {S3} s3 - AWS.S3 instance
16+
* @param {S3Client} s3 - AWS SDK v3 S3Client instance
1617
* @param {S3Object} sourceObj - Object to copy
1718
* @param {string} destBucket - Destination bucket
1819
* @param {string} [destPath] - Destination bucket folder (root if unspecified)
@@ -21,10 +22,10 @@ const getCopyParams = obj => ({
2122
*
2223
* @typedef S3Object
2324
* @property {string} Bucket - Object bucket
24-
* @property {String} Prefix - Deploy folder in bucket
25+
* @property {string} Prefix - Deploy folder in bucket
2526
* @property {string} Key - Full key to object
2627
*/
27-
module.exports = function copyObject(
28+
module.exports = async function copyObject(
2829
s3,
2930
sourceObj,
3031
destBucket,
@@ -37,18 +38,28 @@ module.exports = function copyObject(
3738
const copyParams = getCopyParams(sourceObj)
3839

3940
console.log(
40-
`${dryrun ? 'DRYRUN: ' : ''}Copy
41-
Source: ${copySource}
42-
Dest: /${destBucket}/${destKey}
43-
Params: ${JSON.stringify(copyParams)}\n`
41+
`${
42+
dryrun ? 'DRYRUN: ' : ''
43+
}Copy\nSource: ${copySource}\nDest: /${destBucket}/${destKey}\nParams: ${JSON.stringify(
44+
copyParams
45+
)}\n`
4446
)
4547

4648
if (dryrun) return Promise.resolve()
4749

48-
const copyObjectParams = Object.assign(
49-
{ Bucket: destBucket, Key: destKey, CopySource: copySource },
50-
copyParams
51-
)
50+
const copyObjectParams = {
51+
Bucket: destBucket,
52+
Key: destKey,
53+
CopySource: copySource,
54+
...copyParams,
55+
}
5256

53-
return s3.copyObject(copyObjectParams).promise()
57+
try {
58+
const command = new CopyObjectCommand(copyObjectParams)
59+
await s3.send(command)
60+
console.log(`Successfully copied to /${destBucket}/${destKey}`)
61+
} catch (err) {
62+
console.error(`Error copying object: ${err.message}`)
63+
throw err
64+
}
5465
}

scripts/deploy/lib/removeObject.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict'
22

3+
const { DeleteObjectCommand } = require('@aws-sdk/client-s3');
4+
35
/**
46
* Remove an object from S3
57
*
6-
* @param {AWS.S3} s3 - AWS.S3 instance
8+
* @param {S3Client} s3 - S3Client instance
79
* @param {S3Object} obj - Object to remove
810
* @param {boolean} [dryrun] - Don't actually remove anything
911
* @returns {Promise} Promise that resolves when the removal is complete
@@ -13,13 +15,22 @@
1315
* @property {String} Prefix - Deploy folder in bucket
1416
* @property {string} Key - Full key to object
1517
*/
16-
module.exports = function removeObject(s3, obj, dryrun) {
18+
module.exports = async function removeObject(s3, obj, dryrun) {
1719
console.log(
18-
`${dryrun ? 'DRYRUN: ' : ''}Remove
19-
Source: /${obj.Bucket}/${obj.Key}\n`
20-
)
20+
`${dryrun ? 'DRYRUN: ' : ''}Remove\nSource: /${obj.Bucket}/${obj.Key}\n`
21+
);
22+
23+
if (dryrun) return Promise.resolve();
2124

22-
if (dryrun) return Promise.resolve()
25+
// Construct the deleteObject command with the bucket and key
26+
const deleteParams = { Bucket: obj.Bucket, Key: obj.Key };
2327

24-
return s3.deleteObject({ Bucket: obj.Bucket, Key: obj.Key }).promise()
25-
}
28+
try {
29+
// Use the send method with DeleteObjectCommand
30+
const result = await s3.send(new DeleteObjectCommand(deleteParams));
31+
return result;
32+
} catch (error) {
33+
console.error('Error removing object:', error);
34+
throw error;
35+
}
36+
};

0 commit comments

Comments
 (0)