@cumulus/aws-client 9.4.0 → 9.7.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/Lambda.js CHANGED
@@ -31,6 +31,8 @@ exports.invoke = async (name, payload, type = 'Event') => {
31
31
  FunctionName: name,
32
32
  Payload: JSON.stringify(payload),
33
33
  InvocationType: type,
34
- }).promise();
34
+ })
35
+ .on('error', (error) => log.error(`Error invoking ${name}`, error))
36
+ .promise();
35
37
  };
36
38
  //# sourceMappingURL=Lambda.js.map
package/README.md CHANGED
@@ -894,12 +894,26 @@ errors, to allow more specific handling by the caller.
894
894
  ## SQS
895
895
 
896
896
  * [SQS](#module_SQS)
897
+ * [.sendSQSMessage](#module_SQS.sendSQSMessage) ⇒ <code>Promise</code>
897
898
  * [.deleteSQSMessage](#module_SQS.deleteSQSMessage) ⇒ <code>Promise</code>
898
899
  * [.createQueue(QueueName)](#module_SQS.createQueue) ⇒ <code>Promise.&lt;string&gt;</code>
899
- * [.sendSQSMessage(queueUrl, message)](#module_SQS.sendSQSMessage) ⇒ <code>Promise</code>
900
900
  * [.receiveSQSMessages(queueUrl, options)](#module_SQS.receiveSQSMessages) ⇒ <code>Promise.&lt;Array&gt;</code>
901
901
  * [.sqsQueueExists(queueUrl)](#module_SQS.sqsQueueExists) ⇒ <code>Promise.&lt;boolean&gt;</code>
902
902
 
903
+ <a name="module_SQS.sendSQSMessage"></a>
904
+
905
+ ### SQS.sendSQSMessage ⇒ <code>Promise</code>
906
+ Send a message to AWS SQS
907
+
908
+ **Kind**: static property of [<code>SQS</code>](#module_SQS)
909
+ **Returns**: <code>Promise</code> - resolves when the messsage has been sent
910
+
911
+ | Param | Type | Description |
912
+ | --- | --- | --- |
913
+ | queueUrl | <code>string</code> | url of the SQS queue |
914
+ | message | <code>string</code> \| <code>Object</code> | either string or object message. If an object it will be serialized into a JSON string. |
915
+ | [logOverride] | <code>Logger</code> | optional Logger passed in for testing |
916
+
903
917
  <a name="module_SQS.deleteSQSMessage"></a>
904
918
 
905
919
  ### SQS.deleteSQSMessage ⇒ <code>Promise</code>
@@ -925,19 +939,6 @@ Create an SQS Queue. Properly handles localstack queue URLs
925
939
  | --- | --- | --- |
926
940
  | QueueName | <code>string</code> | queue name |
927
941
 
928
- <a name="module_SQS.sendSQSMessage"></a>
929
-
930
- ### SQS.sendSQSMessage(queueUrl, message) ⇒ <code>Promise</code>
931
- Send a message to AWS SQS
932
-
933
- **Kind**: static method of [<code>SQS</code>](#module_SQS)
934
- **Returns**: <code>Promise</code> - resolves when the messsage has been sent
935
-
936
- | Param | Type | Description |
937
- | --- | --- | --- |
938
- | queueUrl | <code>string</code> | url of the SQS queue |
939
- | message | <code>string</code> \| <code>Object</code> | either string or object message. If an object it will be serialized into a JSON string. |
940
-
941
942
  <a name="module_SQS.receiveSQSMessages"></a>
942
943
 
943
944
  ### SQS.receiveSQSMessages(queueUrl, options) ⇒ <code>Promise.&lt;Array&gt;</code>
package/SQS.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module SQS
3
3
  */
4
+ import Logger from '@cumulus/logger';
4
5
  export interface SQSMessage extends AWS.SQS.Message {
5
6
  ReceiptHandle: string;
6
7
  }
@@ -28,9 +29,11 @@ export declare const getQueueAttributes: (queueName: string) => Promise<{
28
29
  * @param {string} queueUrl - url of the SQS queue
29
30
  * @param {string|Object} message - either string or object message. If an
30
31
  * object it will be serialized into a JSON string.
32
+ * @param {Logger} [logOverride] - optional Logger passed in for testing
31
33
  * @returns {Promise} resolves when the messsage has been sent
34
+
32
35
  **/
33
- export declare const sendSQSMessage: (queueUrl: string, message: string | object) => Promise<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sqs").SendMessageResult, import("aws-sdk").AWSError>>;
36
+ export declare const sendSQSMessage: (queueUrl: string, message: string | object, logOverride: Logger) => Promise<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/sqs").SendMessageResult, import("aws-sdk").AWSError>>;
34
37
  declare type receiveSQSMessagesOptions = {
35
38
  numOfMessages?: number;
36
39
  visibilityTimeout?: number;
package/SQS.js CHANGED
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @module SQS
4
- */
5
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
3
  if (k2 === undefined) k2 = k;
7
4
  Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
@@ -26,6 +23,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
23
  };
27
24
  Object.defineProperty(exports, "__esModule", { value: true });
28
25
  exports.sqsQueueExists = exports.deleteSQSMessage = exports.parseSQSMessageBody = exports.receiveSQSMessages = exports.sendSQSMessage = exports.getQueueAttributes = exports.deleteQueue = exports.createQueue = exports.getQueueUrlByName = exports.getQueueUrl = exports.getQueueNameFromUrl = void 0;
26
+ /**
27
+ * @module SQS
28
+ */
29
+ const logger_1 = __importDefault(require("@cumulus/logger"));
29
30
  const get_1 = __importDefault(require("lodash/get"));
30
31
  const isObject_1 = __importDefault(require("lodash/isObject"));
31
32
  const isString_1 = __importDefault(require("lodash/isString"));
@@ -34,6 +35,7 @@ const url = __importStar(require("url"));
34
35
  const services_1 = require("./services");
35
36
  const test_utils_1 = require("./test-utils");
36
37
  const utils_1 = require("./utils");
38
+ const log = new logger_1.default({ sender: '@cumulus/aws-client/SQS' });
37
39
  exports.getQueueNameFromUrl = (queueUrl) => queueUrl.split('/').pop();
38
40
  exports.getQueueUrl = (sourceArn, queueName) => {
39
41
  const arnParts = sourceArn.split(':');
@@ -54,7 +56,9 @@ exports.getQueueUrlByName = async (queueName) => {
54
56
  async function createQueue(QueueName) {
55
57
  const createQueueResponse = await services_1.sqs().createQueue({
56
58
  QueueName,
57
- }).promise();
59
+ })
60
+ .on('error', (error) => log.error(error))
61
+ .promise();
58
62
  if (test_utils_1.inTestMode()) {
59
63
  if (createQueueResponse.QueueUrl === undefined) {
60
64
  throw new Error('Did not receive a QueueUrl');
@@ -76,7 +80,9 @@ async function createQueue(QueueName) {
76
80
  exports.createQueue = createQueue;
77
81
  exports.deleteQueue = (queueUrl) => services_1.sqs().deleteQueue({
78
82
  QueueUrl: queueUrl,
79
- }).promise();
83
+ })
84
+ .on('error', (error) => log.error(error))
85
+ .promise();
80
86
  exports.getQueueAttributes = async (queueName) => {
81
87
  const queueUrl = await exports.getQueueUrlByName(queueName);
82
88
  if (!queueUrl) {
@@ -97,9 +103,12 @@ exports.getQueueAttributes = async (queueName) => {
97
103
  * @param {string} queueUrl - url of the SQS queue
98
104
  * @param {string|Object} message - either string or object message. If an
99
105
  * object it will be serialized into a JSON string.
106
+ * @param {Logger} [logOverride] - optional Logger passed in for testing
100
107
  * @returns {Promise} resolves when the messsage has been sent
108
+
101
109
  **/
102
- exports.sendSQSMessage = (queueUrl, message) => {
110
+ exports.sendSQSMessage = utils_1.improveStackTrace((queueUrl, message, logOverride) => {
111
+ const logger = logOverride || log;
103
112
  let messageBody;
104
113
  if (isString_1.default(message))
105
114
  messageBody = message;
@@ -110,8 +119,9 @@ exports.sendSQSMessage = (queueUrl, message) => {
110
119
  return services_1.sqs().sendMessage({
111
120
  MessageBody: messageBody,
112
121
  QueueUrl: queueUrl,
113
- }).promise();
114
- };
122
+ }).on('error', (error) => logger.error(error))
123
+ .promise();
124
+ });
115
125
  /**
116
126
  * Receives SQS messages from a given queue. The number of messages received
117
127
  * can be set and the timeout is also adjustable.
@@ -134,7 +144,8 @@ exports.receiveSQSMessages = async (queueUrl, options) => {
134
144
  WaitTimeSeconds: options.waitTimeSeconds || 0,
135
145
  MaxNumberOfMessages: options.numOfMessages || 1,
136
146
  };
137
- const messages = await services_1.sqs().receiveMessage(params).promise();
147
+ const messages = await services_1.sqs().receiveMessage(params)
148
+ .on('error', (error) => log.error(error)).promise();
138
149
  return ((_a = messages.Messages) !== null && _a !== void 0 ? _a : []);
139
150
  };
140
151
  exports.parseSQSMessageBody = (message) => JSON.parse(get_1.default(message, 'Body', get_1.default(message, 'body', '{}')));
@@ -145,7 +156,9 @@ exports.parseSQSMessageBody = (message) => JSON.parse(get_1.default(message, 'Bo
145
156
  * @param {integer} receiptHandle - the unique identifier of the sQS message
146
157
  * @returns {Promise} an AWS SQS response
147
158
  */
148
- exports.deleteSQSMessage = utils_1.improveStackTrace((QueueUrl, ReceiptHandle) => services_1.sqs().deleteMessage({ QueueUrl, ReceiptHandle }).promise());
159
+ exports.deleteSQSMessage = utils_1.improveStackTrace((QueueUrl, ReceiptHandle) => services_1.sqs().deleteMessage({ QueueUrl, ReceiptHandle })
160
+ .on('error', (error) => log.error(error))
161
+ .promise());
149
162
  /**
150
163
  * Test if an SQS queue exists
151
164
  *
@@ -163,8 +176,11 @@ exports.sqsQueueExists = async (queueUrl) => {
163
176
  return true;
164
177
  }
165
178
  catch (error) {
166
- if (error.code === 'AWS.SimpleQueueService.NonExistentQueue')
179
+ if (error.code === 'AWS.SimpleQueueService.NonExistentQueue') {
180
+ log.warn(`Queue ${QueueName} does not exist`);
167
181
  return false;
182
+ }
183
+ log.error(error);
168
184
  throw error;
169
185
  }
170
186
  };
package/client.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const aws_sdk_1 = __importDefault(require("aws-sdk"));
6
6
  const test_utils_1 = require("./test-utils");
7
7
  const noop = () => { }; // eslint-disable-line lodash/prefer-noop
8
- const getRegion = () => process.env.AWS_REGION || 'us-east-1';
8
+ const getRegion = () => process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || 'us-east-1';
9
9
  // Workaround upload hangs. See: https://github.com/andrewrk/node-s3-client/issues/74
10
10
  // @ts-ignore - AWS.util is not part of the public API and may break
11
11
  aws_sdk_1.default.util.update(aws_sdk_1.default.S3.prototype, { addExpect100Continue: noop });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/aws-client",
3
- "version": "9.4.0",
3
+ "version": "9.7.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.4.0",
47
- "@cumulus/errors": "9.4.0",
48
- "@cumulus/logger": "9.4.0",
46
+ "@cumulus/checksum": "9.7.1",
47
+ "@cumulus/errors": "9.7.1",
48
+ "@cumulus/logger": "9.7.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": "a1c0e94e07adf3a5d2c8df93f6f5f216f5ceafe7"
57
+ "gitHead": "926740ad299b43f27117fd1fd34050b3db194c71"
58
58
  }