@cumulus/aws-client 9.2.3 → 9.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/S3.d.ts +12 -0
- package/S3.js +28 -1
- package/S3ObjectStore.js +6 -0
- package/SQS.d.ts +4 -3
- package/SQS.js +7 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -328,6 +328,7 @@ Invoke a Lambda function
|
|
|
328
328
|
* [.s3ObjectExists(params)](#module_S3.s3ObjectExists) ⇒ <code>Promise.<boolean></code>
|
|
329
329
|
* [.waitForObjectToExist(params)](#module_S3.waitForObjectToExist) ⇒ <code>Promise.<undefined></code>
|
|
330
330
|
* [.putFile(bucket, key, filename)](#module_S3.putFile) ⇒ <code>Promise</code>
|
|
331
|
+
* [.streamS3Upload(uploadStream, uploadParams)](#module_S3.streamS3Upload) ⇒ <code>Promise</code>
|
|
331
332
|
* [.downloadS3File(s3Obj, filepath)](#module_S3.downloadS3File) ⇒ <code>Promise.<string></code>
|
|
332
333
|
* [.getObjectSize(params)](#module_S3.getObjectSize) ⇒ <code>Promise.<(number\|undefined)></code>
|
|
333
334
|
* [.getObject(s3, params)](#module_S3.getObject) ⇒ <code>Promise.<AWS.S3.GetObjectOutput></code>
|
|
@@ -559,6 +560,22 @@ Upload a file to S3
|
|
|
559
560
|
| key | <code>string</code> | the destination S3 key |
|
|
560
561
|
| filename | <code>filename</code> | the local file to be uploaded |
|
|
561
562
|
|
|
563
|
+
<a name="module_S3.streamS3Upload"></a>
|
|
564
|
+
|
|
565
|
+
### S3.streamS3Upload(uploadStream, uploadParams) ⇒ <code>Promise</code>
|
|
566
|
+
Upload data to S3 using a stream
|
|
567
|
+
|
|
568
|
+
We are not using `s3.upload().promise()` due to errors observed in testing
|
|
569
|
+
with uncaught exceptions. By creating our own promise, we can ensure any
|
|
570
|
+
errors from the streams or upload cause this promise to reject.
|
|
571
|
+
|
|
572
|
+
**Kind**: static method of [<code>S3</code>](#module_S3)
|
|
573
|
+
|
|
574
|
+
| Param | Type | Description |
|
|
575
|
+
| --- | --- | --- |
|
|
576
|
+
| uploadStream | <code>Readable</code> | Stream of data to upload |
|
|
577
|
+
| uploadParams | <code>Object</code> | see [S3.upload()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property) |
|
|
578
|
+
|
|
562
579
|
<a name="module_S3.downloadS3File"></a>
|
|
563
580
|
|
|
564
581
|
### S3.downloadS3File(s3Obj, filepath) ⇒ <code>Promise.<string></code>
|
|
@@ -881,7 +898,7 @@ errors, to allow more specific handling by the caller.
|
|
|
881
898
|
* [.createQueue(QueueName)](#module_SQS.createQueue) ⇒ <code>Promise.<string></code>
|
|
882
899
|
* [.sendSQSMessage(queueUrl, message)](#module_SQS.sendSQSMessage) ⇒ <code>Promise</code>
|
|
883
900
|
* [.receiveSQSMessages(queueUrl, options)](#module_SQS.receiveSQSMessages) ⇒ <code>Promise.<Array></code>
|
|
884
|
-
* [.sqsQueueExists(
|
|
901
|
+
* [.sqsQueueExists(queueUrl)](#module_SQS.sqsQueueExists) ⇒ <code>Promise.<boolean></code>
|
|
885
902
|
|
|
886
903
|
<a name="module_SQS.deleteSQSMessage"></a>
|
|
887
904
|
|
|
@@ -940,16 +957,16 @@ can be set and the timeout is also adjustable.
|
|
|
940
957
|
|
|
941
958
|
<a name="module_SQS.sqsQueueExists"></a>
|
|
942
959
|
|
|
943
|
-
### SQS.sqsQueueExists(
|
|
960
|
+
### SQS.sqsQueueExists(queueUrl) ⇒ <code>Promise.<boolean></code>
|
|
944
961
|
Test if an SQS queue exists
|
|
945
962
|
|
|
946
963
|
**Kind**: static method of [<code>SQS</code>](#module_SQS)
|
|
947
|
-
**Returns**: <code>Promise.<boolean></code> - a Promise that will resolve to a boolean indicating
|
|
964
|
+
**Returns**: <code>Promise.<boolean></code> - - a Promise that will resolve to a boolean indicating
|
|
948
965
|
if the queue exists
|
|
949
966
|
|
|
950
967
|
| Param | Type | Description |
|
|
951
968
|
| --- | --- | --- |
|
|
952
|
-
|
|
|
969
|
+
| queueUrl | <code>Object</code> | queue url |
|
|
953
970
|
|
|
954
971
|
<a name="module_SecretsManager"></a>
|
|
955
972
|
|
package/S3.d.ts
CHANGED
|
@@ -126,6 +126,18 @@ export declare const s3CopyObject: (params: import("aws-sdk/clients/s3").CopyObj
|
|
|
126
126
|
* @returns {Promise} see [S3.upload()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
|
|
127
127
|
*/
|
|
128
128
|
export declare const promiseS3Upload: (params: import("aws-sdk/clients/s3").PutObjectRequest) => Promise<import("aws-sdk/clients/s3").ManagedUpload.SendData>;
|
|
129
|
+
/**
|
|
130
|
+
* Upload data to S3 using a stream
|
|
131
|
+
*
|
|
132
|
+
* We are not using `s3.upload().promise()` due to errors observed in testing
|
|
133
|
+
* with uncaught exceptions. By creating our own promise, we can ensure any
|
|
134
|
+
* errors from the streams or upload cause this promise to reject.
|
|
135
|
+
*
|
|
136
|
+
* @param {Readable} uploadStream - Stream of data to upload
|
|
137
|
+
* @param {Object} uploadParams - see [S3.upload()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
|
|
138
|
+
* @returns {Promise}
|
|
139
|
+
*/
|
|
140
|
+
export declare const streamS3Upload: (uploadStream: Readable, uploadParams: AWS.S3.PutObjectRequest) => Promise<unknown>;
|
|
129
141
|
/**
|
|
130
142
|
* Downloads the given s3Obj to the given filename in a streaming manner
|
|
131
143
|
*
|
package/S3.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.moveObject = exports.multipartCopyObject = exports.createS3Buckets = exports.createBucket = exports.getFileBucketAndKey = exports.validateS3ObjectChecksum = exports.calculateObjectHash = exports.listS3ObjectsV2 = exports.listS3Objects = exports.uploadS3FileStream = exports.uploadS3Files = exports.deleteS3Buckets = exports.recursivelyDeleteS3Bucket = exports.deleteS3Files = exports.downloadS3Files = exports.fileExists = exports.getObjectReadStream = exports.putJsonS3Object = exports.getJsonS3Object = exports.getTextObject = exports.getS3Object = exports.waitForObject = exports.getObject = exports.s3PutObjectTagging = exports.s3GetObjectTagging = exports.getObjectSize = exports.downloadS3File = exports.promiseS3Upload = exports.s3CopyObject = exports.putFile = exports.s3PutObject = exports.waitForObjectToExist = exports.s3ObjectExists = exports.headObject = exports.deleteS3Object = exports.s3TagSetToQueryString = exports.buildS3Uri = exports.parseS3Uri = exports.s3Join = void 0;
|
|
28
|
+
exports.moveObject = exports.multipartCopyObject = exports.createS3Buckets = exports.createBucket = exports.getFileBucketAndKey = exports.validateS3ObjectChecksum = exports.calculateObjectHash = exports.listS3ObjectsV2 = exports.listS3Objects = exports.uploadS3FileStream = exports.uploadS3Files = exports.deleteS3Buckets = exports.recursivelyDeleteS3Bucket = exports.deleteS3Files = exports.downloadS3Files = exports.fileExists = exports.getObjectReadStream = exports.putJsonS3Object = exports.getJsonS3Object = exports.getTextObject = exports.getS3Object = exports.waitForObject = exports.getObject = exports.s3PutObjectTagging = exports.s3GetObjectTagging = exports.getObjectSize = exports.downloadS3File = exports.streamS3Upload = exports.promiseS3Upload = exports.s3CopyObject = exports.putFile = exports.s3PutObject = exports.waitForObjectToExist = exports.s3ObjectExists = exports.headObject = exports.deleteS3Object = exports.s3TagSetToQueryString = exports.buildS3Uri = exports.parseS3Uri = exports.s3Join = void 0;
|
|
29
29
|
const fs_1 = __importDefault(require("fs"));
|
|
30
30
|
const isBoolean_1 = __importDefault(require("lodash/isBoolean"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
@@ -34,6 +34,7 @@ const p_retry_1 = __importDefault(require("p-retry"));
|
|
|
34
34
|
const p_wait_for_1 = __importDefault(require("p-wait-for"));
|
|
35
35
|
const pump_1 = __importDefault(require("pump"));
|
|
36
36
|
const querystring_1 = __importDefault(require("querystring"));
|
|
37
|
+
const stream_1 = require("stream");
|
|
37
38
|
const util_1 = require("util");
|
|
38
39
|
const checksum_1 = require("@cumulus/checksum");
|
|
39
40
|
const errors_1 = require("@cumulus/errors");
|
|
@@ -204,6 +205,32 @@ exports.s3CopyObject = utils_1.improveStackTrace((params) => services_1.s3().cop
|
|
|
204
205
|
* @returns {Promise} see [S3.upload()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
|
|
205
206
|
*/
|
|
206
207
|
exports.promiseS3Upload = utils_1.improveStackTrace((params) => services_1.s3().upload(params).promise());
|
|
208
|
+
/**
|
|
209
|
+
* Upload data to S3 using a stream
|
|
210
|
+
*
|
|
211
|
+
* We are not using `s3.upload().promise()` due to errors observed in testing
|
|
212
|
+
* with uncaught exceptions. By creating our own promise, we can ensure any
|
|
213
|
+
* errors from the streams or upload cause this promise to reject.
|
|
214
|
+
*
|
|
215
|
+
* @param {Readable} uploadStream - Stream of data to upload
|
|
216
|
+
* @param {Object} uploadParams - see [S3.upload()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property)
|
|
217
|
+
* @returns {Promise}
|
|
218
|
+
*/
|
|
219
|
+
exports.streamS3Upload = (uploadStream, uploadParams) => new Promise((resolve, reject) => {
|
|
220
|
+
const pass = new stream_1.PassThrough();
|
|
221
|
+
uploadStream.pipe(pass);
|
|
222
|
+
uploadStream.on('error', reject);
|
|
223
|
+
pass.on('error', reject);
|
|
224
|
+
return services_1.s3().upload({
|
|
225
|
+
...uploadParams,
|
|
226
|
+
Body: pass,
|
|
227
|
+
}, (err, uploadResponse) => {
|
|
228
|
+
if (err) {
|
|
229
|
+
return reject(err);
|
|
230
|
+
}
|
|
231
|
+
return resolve(uploadResponse);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
207
234
|
/**
|
|
208
235
|
* Downloads the given s3Obj to the given filename in a streaming manner
|
|
209
236
|
*
|
package/S3ObjectStore.js
CHANGED
|
@@ -24,9 +24,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
const querystring = __importStar(require("querystring"));
|
|
25
25
|
const url_1 = require("url");
|
|
26
26
|
const AWS = __importStar(require("aws-sdk"));
|
|
27
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
27
28
|
const S3_1 = require("./S3");
|
|
28
29
|
const client_1 = __importDefault(require("./client"));
|
|
29
30
|
// Code modified from https://github.com/nasa/harmony/blob/main/app/util/object-store.ts
|
|
31
|
+
const log = new logger_1.default({ sender: '@cumulus/aws-client/S3ObjectStore' });
|
|
30
32
|
/**
|
|
31
33
|
* Class to use when interacting with S3
|
|
32
34
|
*
|
|
@@ -46,6 +48,7 @@ class S3ObjectStore {
|
|
|
46
48
|
* @throws TypeError - if the URL is not a recognized protocol or cannot be parsed
|
|
47
49
|
*/
|
|
48
50
|
async signGetObject(objectUrl, options = {}, queryParams) {
|
|
51
|
+
log.info(`Executing signGetObject with objectUrl: ${objectUrl}, options: ${JSON.stringify(options)}, queryParams: ${JSON.stringify(queryParams)}`);
|
|
49
52
|
const url = new url_1.URL(objectUrl);
|
|
50
53
|
if (url.protocol.toLowerCase() !== 's3:') {
|
|
51
54
|
throw new TypeError(`Invalid S3 URL: ${objectUrl}`);
|
|
@@ -58,6 +61,7 @@ class S3ObjectStore {
|
|
|
58
61
|
}
|
|
59
62
|
// TypeScript doesn't recognize that req has a presign method. It does.
|
|
60
63
|
const result = await req.presign();
|
|
64
|
+
log.debug(`Signed GetObject request URL: ${result}`);
|
|
61
65
|
return result;
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
@@ -71,6 +75,7 @@ class S3ObjectStore {
|
|
|
71
75
|
* @throws TypeError - if the URL is not a recognized protocol or cannot be parsed
|
|
72
76
|
*/
|
|
73
77
|
async signHeadObject(objectUrl, options = {}, queryParams) {
|
|
78
|
+
log.info(`Executing signHeadObject with objectUrl: ${objectUrl}, options: ${JSON.stringify(options)}, queryParams: ${JSON.stringify(queryParams)}`);
|
|
74
79
|
const url = new url_1.URL(objectUrl);
|
|
75
80
|
if (url.protocol.toLowerCase() !== 's3:') {
|
|
76
81
|
throw new TypeError(`Invalid S3 URL: ${objectUrl}`);
|
|
@@ -82,6 +87,7 @@ class S3ObjectStore {
|
|
|
82
87
|
}
|
|
83
88
|
// TypeScript doesn't recognize that req has a presign method. It does.
|
|
84
89
|
const result = await req.presign();
|
|
90
|
+
log.debug(`Signed HeadObject request URL: ${result}`);
|
|
85
91
|
return result;
|
|
86
92
|
}
|
|
87
93
|
}
|
package/SQS.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export interface SQSMessage extends AWS.SQS.Message {
|
|
5
5
|
ReceiptHandle: string;
|
|
6
6
|
}
|
|
7
|
+
export declare const getQueueNameFromUrl: (queueUrl: string) => string | undefined;
|
|
7
8
|
export declare const getQueueUrl: (sourceArn: string, queueName: string) => string;
|
|
8
9
|
export declare const getQueueUrlByName: (queueName: string) => Promise<string | undefined>;
|
|
9
10
|
/**
|
|
@@ -62,10 +63,10 @@ export declare const deleteSQSMessage: (QueueUrl: string, ReceiptHandle: string)
|
|
|
62
63
|
/**
|
|
63
64
|
* Test if an SQS queue exists
|
|
64
65
|
*
|
|
65
|
-
* @param {Object}
|
|
66
|
-
* @returns {Promise<boolean>} a Promise that will resolve to a boolean indicating
|
|
66
|
+
* @param {Object} queueUrl - queue url
|
|
67
|
+
* @returns {Promise<boolean>} - a Promise that will resolve to a boolean indicating
|
|
67
68
|
* if the queue exists
|
|
68
69
|
*/
|
|
69
|
-
export declare const sqsQueueExists: (
|
|
70
|
+
export declare const sqsQueueExists: (queueUrl: string) => Promise<boolean>;
|
|
70
71
|
export {};
|
|
71
72
|
//# sourceMappingURL=SQS.d.ts.map
|
package/SQS.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.sqsQueueExists = exports.deleteSQSMessage = exports.parseSQSMessageBody = exports.receiveSQSMessages = exports.sendSQSMessage = exports.getQueueAttributes = exports.deleteQueue = exports.createQueue = exports.getQueueUrlByName = exports.getQueueUrl = void 0;
|
|
28
|
+
exports.sqsQueueExists = exports.deleteSQSMessage = exports.parseSQSMessageBody = exports.receiveSQSMessages = exports.sendSQSMessage = exports.getQueueAttributes = exports.deleteQueue = exports.createQueue = exports.getQueueUrlByName = exports.getQueueUrl = exports.getQueueNameFromUrl = void 0;
|
|
29
29
|
const get_1 = __importDefault(require("lodash/get"));
|
|
30
30
|
const isObject_1 = __importDefault(require("lodash/isObject"));
|
|
31
31
|
const isString_1 = __importDefault(require("lodash/isString"));
|
|
@@ -34,6 +34,7 @@ const url = __importStar(require("url"));
|
|
|
34
34
|
const services_1 = require("./services");
|
|
35
35
|
const test_utils_1 = require("./test-utils");
|
|
36
36
|
const utils_1 = require("./utils");
|
|
37
|
+
exports.getQueueNameFromUrl = (queueUrl) => queueUrl.split('/').pop();
|
|
37
38
|
exports.getQueueUrl = (sourceArn, queueName) => {
|
|
38
39
|
const arnParts = sourceArn.split(':');
|
|
39
40
|
return `https://sqs.${arnParts[3]}.amazonaws.com/${arnParts[4]}/${queueName}`;
|
|
@@ -148,14 +149,14 @@ exports.deleteSQSMessage = utils_1.improveStackTrace((QueueUrl, ReceiptHandle) =
|
|
|
148
149
|
/**
|
|
149
150
|
* Test if an SQS queue exists
|
|
150
151
|
*
|
|
151
|
-
* @param {Object}
|
|
152
|
-
* @returns {Promise<boolean>} a Promise that will resolve to a boolean indicating
|
|
152
|
+
* @param {Object} queueUrl - queue url
|
|
153
|
+
* @returns {Promise<boolean>} - a Promise that will resolve to a boolean indicating
|
|
153
154
|
* if the queue exists
|
|
154
155
|
*/
|
|
155
|
-
exports.sqsQueueExists = async (
|
|
156
|
-
const QueueName =
|
|
156
|
+
exports.sqsQueueExists = async (queueUrl) => {
|
|
157
|
+
const QueueName = exports.getQueueNameFromUrl(queueUrl);
|
|
157
158
|
if (!QueueName) {
|
|
158
|
-
throw new Error(`Unable to determine QueueName from ${
|
|
159
|
+
throw new Error(`Unable to determine QueueName from ${queueUrl}`);
|
|
159
160
|
}
|
|
160
161
|
try {
|
|
161
162
|
await services_1.sqs().getQueueUrl({ QueueName }).promise();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/aws-client",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.1",
|
|
4
4
|
"description": "Utilities for working with AWS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"GIBS",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"author": "Cumulus Authors",
|
|
44
44
|
"license": "Apache-2.0",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@cumulus/checksum": "9.
|
|
47
|
-
"@cumulus/errors": "9.
|
|
48
|
-
"@cumulus/logger": "9.
|
|
46
|
+
"@cumulus/checksum": "9.4.1",
|
|
47
|
+
"@cumulus/errors": "9.4.1",
|
|
48
|
+
"@cumulus/logger": "9.4.1",
|
|
49
49
|
"aws-sdk": "^2.814.0",
|
|
50
50
|
"jsonpath-plus": "^1.1.0",
|
|
51
51
|
"lodash": "~4.17.20",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"p-wait-for": "^3.1.0",
|
|
55
55
|
"pump": "^3.0.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "fce4415918c43a6a14d46ac7d9572f5a97a98a45"
|
|
58
58
|
}
|