@cumulus/aws-client 9.3.0 → 9.4.2

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 CHANGED
@@ -328,6 +328,7 @@ Invoke a Lambda function
328
328
  * [.s3ObjectExists(params)](#module_S3.s3ObjectExists) ⇒ <code>Promise.&lt;boolean&gt;</code>
329
329
  * [.waitForObjectToExist(params)](#module_S3.waitForObjectToExist) ⇒ <code>Promise.&lt;undefined&gt;</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.&lt;string&gt;</code>
332
333
  * [.getObjectSize(params)](#module_S3.getObjectSize) ⇒ <code>Promise.&lt;(number\|undefined)&gt;</code>
333
334
  * [.getObject(s3, params)](#module_S3.getObject) ⇒ <code>Promise.&lt;AWS.S3.GetObjectOutput&gt;</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.&lt;string&gt;</code>
@@ -881,7 +898,7 @@ errors, to allow more specific handling by the caller.
881
898
  * [.createQueue(QueueName)](#module_SQS.createQueue) ⇒ <code>Promise.&lt;string&gt;</code>
882
899
  * [.sendSQSMessage(queueUrl, message)](#module_SQS.sendSQSMessage) ⇒ <code>Promise</code>
883
900
  * [.receiveSQSMessages(queueUrl, options)](#module_SQS.receiveSQSMessages) ⇒ <code>Promise.&lt;Array&gt;</code>
884
- * [.sqsQueueExists(queue)](#module_SQS.sqsQueueExists) ⇒ <code>Promise.&lt;boolean&gt;</code>
901
+ * [.sqsQueueExists(queueUrl)](#module_SQS.sqsQueueExists) ⇒ <code>Promise.&lt;boolean&gt;</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(queue) ⇒ <code>Promise.&lt;boolean&gt;</code>
960
+ ### SQS.sqsQueueExists(queueUrl) ⇒ <code>Promise.&lt;boolean&gt;</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.&lt;boolean&gt;</code> - a Promise that will resolve to a boolean indicating
964
+ **Returns**: <code>Promise.&lt;boolean&gt;</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
- | queue | <code>Object</code> | queue name or url |
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/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} queue - queue name or url
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: (queue: string) => Promise<boolean>;
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} queue - queue name or url
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 (queue) => {
156
- const QueueName = queue.split('/').pop();
156
+ exports.sqsQueueExists = async (queueUrl) => {
157
+ const QueueName = exports.getQueueNameFromUrl(queueUrl);
157
158
  if (!QueueName) {
158
- throw new Error(`Unable to determine QueueName from ${queue}`);
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.0",
3
+ "version": "9.4.2",
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.3.0",
47
- "@cumulus/errors": "9.3.0",
48
- "@cumulus/logger": "9.3.0",
46
+ "@cumulus/checksum": "9.4.2",
47
+ "@cumulus/errors": "9.4.2",
48
+ "@cumulus/logger": "9.4.2",
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": "1e0ecaff0e7107e3c5a83f0479972bca0f223842"
57
+ "gitHead": "93ac169ad2ef47ea3ba207e686d9aa870c5d8bcc"
58
58
  }