@cumulus/aws-client 18.2.2 → 18.3.0
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/CloudFormationGateway.d.ts +3 -2
- package/CloudFormationGateway.js +1 -1
- package/Lambda.d.ts +10 -8
- package/Lambda.js +14 -10
- package/README.md +113 -103
- package/S3.d.ts +40 -31
- package/S3.js +69 -44
- package/SNS.d.ts +4 -4
- package/SNS.js +13 -10
- package/SQS.d.ts +13 -33
- package/SQS.js +43 -50
- package/STS.d.ts +5 -0
- package/STS.js +6 -0
- package/SecretsManager.js +1 -1
- package/StepFunctions.d.ts +17 -17
- package/StepFunctions.js +15 -14
- package/client.d.ts +1 -3
- package/client.js +1 -12
- package/lib/S3MultipartUploads.d.ts +3 -3
- package/package.json +17 -9
- package/services.d.ts +18 -16
- package/services.js +19 -40
- package/test-utils.d.ts +6 -8
- package/test-utils.js +6 -8
- package/types.d.ts +7 -2
package/S3.js
CHANGED
|
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.moveObject = exports.multipartCopyObject = exports.createS3Buckets = exports.createBucket = exports.getFileBucketAndKey = exports.validateS3ObjectChecksum = exports.calculateObjectHash = exports.
|
|
32
|
+
exports.moveObject = exports.multipartCopyObject = exports.createS3Buckets = exports.createBucket = exports.getFileBucketAndKey = exports.validateS3ObjectChecksum = exports.calculateObjectHash = exports.deleteS3Buckets = exports.recursivelyDeleteS3Bucket = exports.listS3ObjectsV2Batch = exports.listS3ObjectsV2 = exports.listS3Objects = exports.uploadS3FileStream = exports.uploadS3Files = exports.deleteS3Files = exports.fileExists = exports.putJsonS3Object = exports.getJsonS3Object = exports.getTextObject = exports.getObjectStreamContents = exports.getObjectStreamBuffers = exports.getS3Object = exports.waitForObject = exports.getObject = exports.s3PutObjectTagging = exports.s3GetObjectTagging = exports.getObjectSize = exports.downloadS3File = exports.getObjectReadStream = exports.streamS3Upload = exports.promiseS3Upload = exports.s3CopyObject = exports.putFile = exports.s3PutObject = exports.waitForObjectToExist = exports.s3ObjectExists = exports.headObject = exports.deleteS3Objects = exports.deleteS3Object = exports.s3TagSetToQueryString = exports.buildS3Uri = exports.parseS3Uri = exports.s3Join = void 0;
|
|
33
33
|
const fs_1 = __importDefault(require("fs"));
|
|
34
34
|
const isBoolean_1 = __importDefault(require("lodash/isBoolean"));
|
|
35
35
|
const path_1 = __importDefault(require("path"));
|
|
@@ -140,12 +140,12 @@ exports.deleteS3Objects = deleteS3Objects;
|
|
|
140
140
|
/**
|
|
141
141
|
* Get an object header from S3
|
|
142
142
|
*
|
|
143
|
-
* @param
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
143
|
+
* @param Bucket - name of bucket
|
|
144
|
+
* @param Key - key for object (filepath + filename)
|
|
145
|
+
* @param retryOptions - options to control retry behavior when an
|
|
146
146
|
* object does not exist. See https://github.com/tim-kos/node-retry#retryoperationoptions
|
|
147
147
|
* By default, retries will not be performed
|
|
148
|
-
* @returns
|
|
148
|
+
* @returns returns response from `S3.headObject` as a promise
|
|
149
149
|
**/
|
|
150
150
|
const headObject = (Bucket, Key, retryOptions = { retries: 0 }) => (0, p_retry_1.default)(async () => {
|
|
151
151
|
try {
|
|
@@ -517,33 +517,6 @@ exports.fileExists = fileExists;
|
|
|
517
517
|
*/
|
|
518
518
|
const deleteS3Files = async (s3Objs) => await (0, p_map_1.default)(s3Objs, (s3Obj) => (0, services_1.s3)().deleteObject(s3Obj), { concurrency: S3_RATE_LIMIT });
|
|
519
519
|
exports.deleteS3Files = deleteS3Files;
|
|
520
|
-
/**
|
|
521
|
-
* Delete a bucket and all of its objects from S3
|
|
522
|
-
*
|
|
523
|
-
* @param {string} bucket - name of the bucket
|
|
524
|
-
* @returns {Promise} the promised result of `S3.deleteBucket`
|
|
525
|
-
**/
|
|
526
|
-
exports.recursivelyDeleteS3Bucket = (0, utils_1.improveStackTrace)(async (bucket) => {
|
|
527
|
-
const response = await (0, services_1.s3)().listObjects({ Bucket: bucket });
|
|
528
|
-
const s3Objects = (response.Contents || []).map((o) => {
|
|
529
|
-
if (!o.Key)
|
|
530
|
-
throw new Error(`Unable to determine S3 key of ${JSON.stringify(o)}`);
|
|
531
|
-
return {
|
|
532
|
-
Bucket: bucket,
|
|
533
|
-
Key: o.Key,
|
|
534
|
-
};
|
|
535
|
-
});
|
|
536
|
-
await (0, exports.deleteS3Files)(s3Objects);
|
|
537
|
-
return await (0, services_1.s3)().deleteBucket({ Bucket: bucket });
|
|
538
|
-
});
|
|
539
|
-
/**
|
|
540
|
-
* Delete a list of buckets and all of their objects from S3
|
|
541
|
-
*
|
|
542
|
-
* @param {Array} buckets - list of bucket names
|
|
543
|
-
* @returns {Promise} the promised result of `S3.deleteBucket`
|
|
544
|
-
**/
|
|
545
|
-
const deleteS3Buckets = async (buckets) => await Promise.all(buckets.map(exports.recursivelyDeleteS3Bucket));
|
|
546
|
-
exports.deleteS3Buckets = deleteS3Buckets;
|
|
547
520
|
const uploadS3Files = async (files, defaultBucket, keyPath, s3opts = {}) => {
|
|
548
521
|
let i = 0;
|
|
549
522
|
const n = files.length;
|
|
@@ -604,15 +577,6 @@ const uploadS3FileStream = (fileStream, bucket, key, s3opts = {}) => (0, exports
|
|
|
604
577
|
exports.uploadS3FileStream = uploadS3FileStream;
|
|
605
578
|
/**
|
|
606
579
|
* List the objects in an S3 bucket
|
|
607
|
-
*
|
|
608
|
-
* @param {string} bucket - The name of the bucket
|
|
609
|
-
* @param {string} prefix - Only objects with keys starting with this prefix
|
|
610
|
-
* will be included (useful for searching folders in buckets, e.g., '/PDR')
|
|
611
|
-
* @param {boolean} skipFolders - If true don't return objects that are folders
|
|
612
|
-
* (defaults to true)
|
|
613
|
-
* @returns {Promise} A promise that resolves to the list of objects. Each S3
|
|
614
|
-
* object is represented as a JS object with the following attributes: `Key`,
|
|
615
|
-
* `ETag`, `LastModified`, `Owner`, `Size`, `StorageClass`.
|
|
616
580
|
*/
|
|
617
581
|
const listS3Objects = async (bucket, prefix, skipFolders = true) => {
|
|
618
582
|
log.info(`Listing objects in s3://${bucket}`);
|
|
@@ -622,10 +586,13 @@ const listS3Objects = async (bucket, prefix, skipFolders = true) => {
|
|
|
622
586
|
if (prefix)
|
|
623
587
|
params.Prefix = prefix;
|
|
624
588
|
const data = await (0, services_1.s3)().listObjects(params);
|
|
625
|
-
|
|
589
|
+
if (!data.Contents) {
|
|
590
|
+
return [];
|
|
591
|
+
}
|
|
592
|
+
let contents = data.Contents.filter((obj) => obj.Key !== undefined);
|
|
626
593
|
if (skipFolders) {
|
|
627
594
|
// Filter out any references to folders
|
|
628
|
-
contents = contents.filter((obj) => obj.Key
|
|
595
|
+
contents = contents.filter((obj) => obj.Key && !obj.Key.endsWith('/'));
|
|
629
596
|
}
|
|
630
597
|
return contents;
|
|
631
598
|
};
|
|
@@ -661,9 +628,67 @@ const listS3ObjectsV2 = async (params) => {
|
|
|
661
628
|
}));
|
|
662
629
|
discoveredObjects = discoveredObjects.concat(listObjectsResponse.Contents ?? []);
|
|
663
630
|
}
|
|
664
|
-
return discoveredObjects;
|
|
631
|
+
return discoveredObjects.filter((obj) => obj.Key);
|
|
665
632
|
};
|
|
666
633
|
exports.listS3ObjectsV2 = listS3ObjectsV2;
|
|
634
|
+
/**
|
|
635
|
+
* Fetch lazy list of S3 objects
|
|
636
|
+
*
|
|
637
|
+
* listObjectsV2 is limited to 1,000 results per call. This function continues
|
|
638
|
+
* listing objects until there are no more to be fetched.
|
|
639
|
+
*
|
|
640
|
+
* The passed params must be compatible with the listObjectsV2 call.
|
|
641
|
+
*
|
|
642
|
+
* https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjectsV2-property
|
|
643
|
+
*
|
|
644
|
+
* @param params - params for the s3.listObjectsV2 call
|
|
645
|
+
* @yields a series of objects corresponding to
|
|
646
|
+
* the Contents property of the listObjectsV2 response
|
|
647
|
+
* batched to allow processing of one chunk at a time
|
|
648
|
+
*
|
|
649
|
+
* @static
|
|
650
|
+
*/
|
|
651
|
+
async function* listS3ObjectsV2Batch(params) {
|
|
652
|
+
let listObjectsResponse = await (0, services_1.s3)().listObjectsV2(params);
|
|
653
|
+
let discoveredObjects = listObjectsResponse.Contents ?? [];
|
|
654
|
+
yield discoveredObjects.filter((obj) => 'Key' in obj);
|
|
655
|
+
// Keep listing more objects from S3 until we have all of them
|
|
656
|
+
while (listObjectsResponse.IsTruncated) {
|
|
657
|
+
// eslint-disable-next-line no-await-in-loop
|
|
658
|
+
listObjectsResponse = (await (0, services_1.s3)().listObjectsV2(
|
|
659
|
+
// Update the params with a Continuation Token
|
|
660
|
+
{
|
|
661
|
+
...params,
|
|
662
|
+
ContinuationToken: listObjectsResponse.NextContinuationToken,
|
|
663
|
+
}));
|
|
664
|
+
discoveredObjects = listObjectsResponse.Contents ?? [];
|
|
665
|
+
yield discoveredObjects.filter((obj) => 'Key' in obj);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
exports.listS3ObjectsV2Batch = listS3ObjectsV2Batch;
|
|
669
|
+
/**
|
|
670
|
+
* Delete a bucket and all of its objects from S3
|
|
671
|
+
*
|
|
672
|
+
* @param bucket - name of the bucket
|
|
673
|
+
* @returns the promised result of `S3.deleteBucket`
|
|
674
|
+
**/
|
|
675
|
+
exports.recursivelyDeleteS3Bucket = (0, utils_1.improveStackTrace)(async (bucket) => {
|
|
676
|
+
for await (const objectBatch of listS3ObjectsV2Batch({ Bucket: bucket })) {
|
|
677
|
+
if (objectBatch) {
|
|
678
|
+
const deleteRequests = objectBatch.filter((obj) => obj.Key).map((obj) => ({ Bucket: bucket, Key: obj.Key }));
|
|
679
|
+
await (0, exports.deleteS3Files)(deleteRequests);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return await (0, services_1.s3)().deleteBucket({ Bucket: bucket });
|
|
683
|
+
});
|
|
684
|
+
/**
|
|
685
|
+
* Delete a list of buckets and all of their objects from S3
|
|
686
|
+
*
|
|
687
|
+
* @param {Array} buckets - list of bucket names
|
|
688
|
+
* @returns {Promise} the promised result of `S3.deleteBucket`
|
|
689
|
+
**/
|
|
690
|
+
const deleteS3Buckets = async (buckets) => await Promise.all(buckets.map(exports.recursivelyDeleteS3Bucket));
|
|
691
|
+
exports.deleteS3Buckets = deleteS3Buckets;
|
|
667
692
|
/**
|
|
668
693
|
* Calculate the cryptographic hash of an S3 object
|
|
669
694
|
*
|
package/SNS.d.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* Publish a message to an SNS topic. Does not catch
|
|
6
6
|
* errors, to allow more specific handling by the caller.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
8
|
+
* @param snsTopicArn - SNS topic ARN
|
|
9
|
+
* @param message - Message object
|
|
10
|
+
* @param retryOptions - options to control retry behavior when publishing
|
|
11
11
|
* a message fails. See https://github.com/tim-kos/node-retry#retryoperationoptions
|
|
12
12
|
* @returns {Promise<undefined>}
|
|
13
13
|
*/
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const publishSnsMessageWithRetry: (snsTopicArn: string, message: Object, retryOptions?: {}) => Promise<void>;
|
|
15
15
|
/**
|
|
16
16
|
* Create an SNS topic with a given name.
|
|
17
17
|
*
|
package/SNS.js
CHANGED
|
@@ -6,35 +6,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createSnsTopic = exports.
|
|
9
|
+
exports.createSnsTopic = exports.publishSnsMessageWithRetry = void 0;
|
|
10
10
|
const p_retry_1 = __importDefault(require("p-retry"));
|
|
11
11
|
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
12
|
+
const client_sns_1 = require("@aws-sdk/client-sns");
|
|
12
13
|
const services_1 = require("./services");
|
|
13
14
|
const log = new logger_1.default({ sender: 'aws-client/sns' });
|
|
14
15
|
/**
|
|
15
16
|
* Publish a message to an SNS topic. Does not catch
|
|
16
17
|
* errors, to allow more specific handling by the caller.
|
|
17
18
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
19
|
+
* @param snsTopicArn - SNS topic ARN
|
|
20
|
+
* @param message - Message object
|
|
21
|
+
* @param retryOptions - options to control retry behavior when publishing
|
|
21
22
|
* a message fails. See https://github.com/tim-kos/node-retry#retryoperationoptions
|
|
22
23
|
* @returns {Promise<undefined>}
|
|
23
24
|
*/
|
|
24
|
-
const
|
|
25
|
+
const publishSnsMessageWithRetry = async (snsTopicArn, message, retryOptions = {}) => await (0, p_retry_1.default)(async () => {
|
|
25
26
|
if (!snsTopicArn) {
|
|
26
27
|
throw new p_retry_1.default.AbortError('Missing SNS topic ARN');
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
const publishInput = {
|
|
29
30
|
TopicArn: snsTopicArn,
|
|
30
31
|
Message: JSON.stringify(message),
|
|
31
|
-
}
|
|
32
|
+
};
|
|
33
|
+
await (0, services_1.sns)().send(new client_sns_1.PublishCommand(publishInput));
|
|
32
34
|
}, {
|
|
33
35
|
maxTimeout: 5000,
|
|
34
|
-
onFailedAttempt: (err) => log.debug(`
|
|
36
|
+
onFailedAttempt: (err) => log.debug(`publishSnsMessageWithRetry('${snsTopicArn}', '${JSON.stringify(message)}') failed with ${err.retriesLeft} retries left: ${JSON.stringify(err)}`),
|
|
35
37
|
...retryOptions,
|
|
36
38
|
});
|
|
37
|
-
exports.
|
|
39
|
+
exports.publishSnsMessageWithRetry = publishSnsMessageWithRetry;
|
|
38
40
|
/**
|
|
39
41
|
* Create an SNS topic with a given name.
|
|
40
42
|
*
|
|
@@ -46,7 +48,8 @@ const createSnsTopic = async (snsTopicName) => {
|
|
|
46
48
|
Name: snsTopicName,
|
|
47
49
|
KmsMasterKeyId: 'alias/aws/sns',
|
|
48
50
|
};
|
|
49
|
-
const
|
|
51
|
+
const createTopicCommand = new client_sns_1.CreateTopicCommand(createTopicInput);
|
|
52
|
+
const createTopicResponse = await (0, services_1.sns)().send(createTopicCommand);
|
|
50
53
|
return { TopicArn: createTopicResponse.TopicArn };
|
|
51
54
|
};
|
|
52
55
|
exports.createSnsTopic = createSnsTopic;
|
package/SQS.d.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* @module SQS
|
|
3
3
|
*/
|
|
4
4
|
import Logger from '@cumulus/logger';
|
|
5
|
+
import { CumulusMessage } from '@cumulus/types/message';
|
|
5
6
|
import { SQSRecord } from 'aws-lambda';
|
|
6
|
-
|
|
7
|
+
import { Message } from '@aws-sdk/client-sqs';
|
|
8
|
+
import { StepFunctionEventBridgeEvent } from './Lambda';
|
|
9
|
+
export interface SQSMessage extends Message {
|
|
7
10
|
ReceiptHandle: string;
|
|
8
11
|
}
|
|
9
12
|
export declare const getQueueNameFromUrl: (queueUrl: string) => string | undefined;
|
|
@@ -11,11 +14,6 @@ export declare const getQueueUrl: (sourceArn: string, queueName: string) => stri
|
|
|
11
14
|
export declare const getQueueUrlByName: (queueName: string) => Promise<string | undefined>;
|
|
12
15
|
/**
|
|
13
16
|
* Create an SQS Queue. Properly handles localstack queue URLs
|
|
14
|
-
*
|
|
15
|
-
* @param {string} QueueName - queue name
|
|
16
|
-
* @returns {Promise<string>} the Queue URL
|
|
17
|
-
*
|
|
18
|
-
* @static
|
|
19
17
|
*/
|
|
20
18
|
export declare function createQueue(QueueName: string): Promise<string | undefined>;
|
|
21
19
|
export declare const deleteQueue: (queueUrl: string) => Promise<import("@aws-sdk/client-sqs").DeleteQueueCommandOutput>;
|
|
@@ -46,15 +44,8 @@ export declare const getQueueAttributes: (queueName: string) => Promise<{
|
|
|
46
44
|
}>;
|
|
47
45
|
/**
|
|
48
46
|
* Send a message to AWS SQS
|
|
49
|
-
*
|
|
50
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
51
|
-
* @param {string|Object} message - either string or object message. If an
|
|
52
|
-
* object it will be serialized into a JSON string.
|
|
53
|
-
* @param {Logger} [logOverride] - optional Logger passed in for testing
|
|
54
|
-
* @returns {Promise} resolves when the messsage has been sent
|
|
55
|
-
|
|
56
47
|
**/
|
|
57
|
-
export declare const sendSQSMessage: (queueUrl: string, message: string | object, logOverride
|
|
48
|
+
export declare const sendSQSMessage: (queueUrl: string, message: string | object, logOverride?: Logger | undefined) => Promise<import("@aws-sdk/client-sqs").SendMessageCommandOutput>;
|
|
58
49
|
declare type ReceiveSQSMessagesOptions = {
|
|
59
50
|
numOfMessages?: number;
|
|
60
51
|
visibilityTimeout?: number;
|
|
@@ -63,33 +54,22 @@ declare type ReceiveSQSMessagesOptions = {
|
|
|
63
54
|
/**
|
|
64
55
|
* Receives SQS messages from a given queue. The number of messages received
|
|
65
56
|
* can be set and the timeout is also adjustable.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
68
|
-
* @param {Object} options - options object
|
|
69
|
-
* @param {integer} [options.numOfMessages=1] - number of messages to read from the queue
|
|
70
|
-
* @param {integer} [options.visibilityTimeout=30] - number of seconds a message is invisible
|
|
71
|
-
* after read
|
|
72
|
-
* @param {integer} [options.waitTimeSeconds=0] - number of seconds to poll SQS queue (long polling)
|
|
73
|
-
* @returns {Promise<Array>} an array of messages
|
|
74
57
|
*/
|
|
75
58
|
export declare const receiveSQSMessages: (queueUrl: string, options: ReceiveSQSMessagesOptions) => Promise<SQSMessage[]>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Bare check for SQS message Shape
|
|
61
|
+
*/
|
|
62
|
+
export declare const isSQSRecordLike: (message: Object) => message is SQSRecord;
|
|
63
|
+
/**
|
|
64
|
+
* Extract SQS message body
|
|
65
|
+
*/
|
|
66
|
+
export declare const parseSQSMessageBody: (message: SQSRecord | Message) => StepFunctionEventBridgeEvent | CumulusMessage | SQSRecord;
|
|
79
67
|
/**
|
|
80
68
|
* Delete a given SQS message from a given queue.
|
|
81
|
-
*
|
|
82
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
83
|
-
* @param {integer} receiptHandle - the unique identifier of the sQS message
|
|
84
|
-
* @returns {Promise} an AWS SQS response
|
|
85
69
|
*/
|
|
86
70
|
export declare const deleteSQSMessage: (QueueUrl: string, ReceiptHandle: string) => Promise<import("@aws-sdk/client-sqs").DeleteMessageCommandOutput>;
|
|
87
71
|
/**
|
|
88
72
|
* Test if an SQS queue exists
|
|
89
|
-
*
|
|
90
|
-
* @param {Object} queueUrl - queue url
|
|
91
|
-
* @returns {Promise<boolean>} - a Promise that will resolve to a boolean indicating
|
|
92
|
-
* if the queue exists
|
|
93
73
|
*/
|
|
94
74
|
export declare const sqsQueueExists: (queueUrl: string) => Promise<boolean>;
|
|
95
75
|
export {};
|
package/SQS.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sqsQueueExists = exports.deleteSQSMessage = exports.parseSQSMessageBody = exports.receiveSQSMessages = exports.sendSQSMessage = exports.getQueueAttributes = exports.deleteQueue = exports.createQueue = exports.getQueueUrlByName = exports.getQueueUrl = exports.getQueueNameFromUrl = void 0;
|
|
6
|
+
exports.sqsQueueExists = exports.deleteSQSMessage = exports.parseSQSMessageBody = exports.isSQSRecordLike = exports.receiveSQSMessages = exports.sendSQSMessage = exports.getQueueAttributes = exports.deleteQueue = exports.createQueue = exports.getQueueUrlByName = exports.getQueueUrl = exports.getQueueNameFromUrl = void 0;
|
|
7
|
+
//@ts-check
|
|
7
8
|
/**
|
|
8
9
|
* @module SQS
|
|
9
10
|
*/
|
|
@@ -23,44 +24,43 @@ const getQueueUrl = (sourceArn, queueName) => {
|
|
|
23
24
|
};
|
|
24
25
|
exports.getQueueUrl = getQueueUrl;
|
|
25
26
|
const getQueueUrlByName = async (queueName) => {
|
|
26
|
-
const
|
|
27
|
+
const command = new client_sqs_1.GetQueueUrlCommand({ QueueName: queueName });
|
|
28
|
+
const response = await (0, services_1.sqs)().send(command);
|
|
27
29
|
return response.QueueUrl;
|
|
28
30
|
};
|
|
29
31
|
exports.getQueueUrlByName = getQueueUrlByName;
|
|
30
32
|
/**
|
|
31
33
|
* Create an SQS Queue. Properly handles localstack queue URLs
|
|
32
|
-
*
|
|
33
|
-
* @param {string} QueueName - queue name
|
|
34
|
-
* @returns {Promise<string>} the Queue URL
|
|
35
|
-
*
|
|
36
|
-
* @static
|
|
37
34
|
*/
|
|
38
35
|
async function createQueue(QueueName) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const command = new client_sqs_1.CreateQueueCommand({ QueueName });
|
|
37
|
+
const createQueueResponse = await (0, services_1.sqs)().send(command)
|
|
38
|
+
.catch((error) => {
|
|
42
39
|
log.error(error);
|
|
43
40
|
throw error;
|
|
44
41
|
});
|
|
45
42
|
return createQueueResponse.QueueUrl;
|
|
46
43
|
}
|
|
47
44
|
exports.createQueue = createQueue;
|
|
48
|
-
const deleteQueue = (queueUrl) =>
|
|
49
|
-
QueueUrl: queueUrl
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const deleteQueue = (queueUrl) => {
|
|
46
|
+
const command = new client_sqs_1.DeleteQueueCommand({ QueueUrl: queueUrl });
|
|
47
|
+
return (0, services_1.sqs)().send(command)
|
|
48
|
+
.catch((error) => {
|
|
49
|
+
log.error(error);
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
54
53
|
exports.deleteQueue = deleteQueue;
|
|
55
54
|
const getQueueAttributes = async (queueName) => {
|
|
56
55
|
const queueUrl = await (0, exports.getQueueUrlByName)(queueName);
|
|
57
56
|
if (!queueUrl) {
|
|
58
57
|
throw new Error(`Unable to determine QueueUrl of ${queueName}`);
|
|
59
58
|
}
|
|
60
|
-
const
|
|
59
|
+
const command = new client_sqs_1.GetQueueAttributesCommand({
|
|
61
60
|
AttributeNames: ['All'],
|
|
62
61
|
QueueUrl: queueUrl,
|
|
63
62
|
});
|
|
63
|
+
const response = await (0, services_1.sqs)().send(command);
|
|
64
64
|
return {
|
|
65
65
|
...response.Attributes,
|
|
66
66
|
name: queueName,
|
|
@@ -69,15 +69,8 @@ const getQueueAttributes = async (queueName) => {
|
|
|
69
69
|
exports.getQueueAttributes = getQueueAttributes;
|
|
70
70
|
/**
|
|
71
71
|
* Send a message to AWS SQS
|
|
72
|
-
*
|
|
73
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
74
|
-
* @param {string|Object} message - either string or object message. If an
|
|
75
|
-
* object it will be serialized into a JSON string.
|
|
76
|
-
* @param {Logger} [logOverride] - optional Logger passed in for testing
|
|
77
|
-
* @returns {Promise} resolves when the messsage has been sent
|
|
78
|
-
|
|
79
72
|
**/
|
|
80
|
-
const sendSQSMessage = (queueUrl, message, logOverride) => {
|
|
73
|
+
const sendSQSMessage = (queueUrl, message, logOverride = undefined) => {
|
|
81
74
|
const logger = logOverride || log;
|
|
82
75
|
let messageBody;
|
|
83
76
|
if ((0, isString_1.default)(message))
|
|
@@ -86,10 +79,12 @@ const sendSQSMessage = (queueUrl, message, logOverride) => {
|
|
|
86
79
|
messageBody = JSON.stringify(message);
|
|
87
80
|
else
|
|
88
81
|
throw new Error('body type is not accepted');
|
|
89
|
-
|
|
82
|
+
const command = new client_sqs_1.SendMessageCommand({
|
|
90
83
|
MessageBody: messageBody,
|
|
91
84
|
QueueUrl: queueUrl,
|
|
92
|
-
})
|
|
85
|
+
});
|
|
86
|
+
return (0, services_1.sqs)().send(command)
|
|
87
|
+
.catch((error) => {
|
|
93
88
|
logger.error(error);
|
|
94
89
|
throw error;
|
|
95
90
|
});
|
|
@@ -98,14 +93,6 @@ exports.sendSQSMessage = sendSQSMessage;
|
|
|
98
93
|
/**
|
|
99
94
|
* Receives SQS messages from a given queue. The number of messages received
|
|
100
95
|
* can be set and the timeout is also adjustable.
|
|
101
|
-
*
|
|
102
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
103
|
-
* @param {Object} options - options object
|
|
104
|
-
* @param {integer} [options.numOfMessages=1] - number of messages to read from the queue
|
|
105
|
-
* @param {integer} [options.visibilityTimeout=30] - number of seconds a message is invisible
|
|
106
|
-
* after read
|
|
107
|
-
* @param {integer} [options.waitTimeSeconds=0] - number of seconds to poll SQS queue (long polling)
|
|
108
|
-
* @returns {Promise<Array>} an array of messages
|
|
109
96
|
*/
|
|
110
97
|
const receiveSQSMessages = async (queueUrl, options) => {
|
|
111
98
|
const params = {
|
|
@@ -116,7 +103,8 @@ const receiveSQSMessages = async (queueUrl, options) => {
|
|
|
116
103
|
WaitTimeSeconds: options.waitTimeSeconds || 0,
|
|
117
104
|
MaxNumberOfMessages: options.numOfMessages || 1,
|
|
118
105
|
};
|
|
119
|
-
const
|
|
106
|
+
const command = new client_sqs_1.ReceiveMessageCommand(params);
|
|
107
|
+
const messages = await (0, services_1.sqs)().send(command)
|
|
120
108
|
.catch((error) => {
|
|
121
109
|
log.error(error);
|
|
122
110
|
throw error;
|
|
@@ -124,35 +112,40 @@ const receiveSQSMessages = async (queueUrl, options) => {
|
|
|
124
112
|
return (messages.Messages ?? []);
|
|
125
113
|
};
|
|
126
114
|
exports.receiveSQSMessages = receiveSQSMessages;
|
|
115
|
+
/**
|
|
116
|
+
* Bare check for SQS message Shape
|
|
117
|
+
*/
|
|
118
|
+
const isSQSRecordLike = (message) => (message instanceof Object
|
|
119
|
+
&& ('body' in message || 'Body' in message));
|
|
120
|
+
exports.isSQSRecordLike = isSQSRecordLike;
|
|
121
|
+
/**
|
|
122
|
+
* Extract SQS message body
|
|
123
|
+
*/
|
|
127
124
|
const parseSQSMessageBody = (message) => JSON.parse((0, get_1.default)(message, 'Body', (0, get_1.default)(message, 'body')) ?? '{}');
|
|
128
125
|
exports.parseSQSMessageBody = parseSQSMessageBody;
|
|
129
126
|
/**
|
|
130
127
|
* Delete a given SQS message from a given queue.
|
|
131
|
-
*
|
|
132
|
-
* @param {string} queueUrl - url of the SQS queue
|
|
133
|
-
* @param {integer} receiptHandle - the unique identifier of the sQS message
|
|
134
|
-
* @returns {Promise} an AWS SQS response
|
|
135
128
|
*/
|
|
136
|
-
const deleteSQSMessage = (QueueUrl, ReceiptHandle) =>
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
const deleteSQSMessage = (QueueUrl, ReceiptHandle) => {
|
|
130
|
+
const command = new client_sqs_1.DeleteMessageCommand({ QueueUrl, ReceiptHandle });
|
|
131
|
+
return (0, services_1.sqs)().send(command)
|
|
132
|
+
.catch((error) => {
|
|
133
|
+
log.error(error);
|
|
134
|
+
throw error;
|
|
135
|
+
});
|
|
136
|
+
};
|
|
141
137
|
exports.deleteSQSMessage = deleteSQSMessage;
|
|
142
138
|
/**
|
|
143
139
|
* Test if an SQS queue exists
|
|
144
|
-
*
|
|
145
|
-
* @param {Object} queueUrl - queue url
|
|
146
|
-
* @returns {Promise<boolean>} - a Promise that will resolve to a boolean indicating
|
|
147
|
-
* if the queue exists
|
|
148
140
|
*/
|
|
149
141
|
const sqsQueueExists = async (queueUrl) => {
|
|
150
142
|
const QueueName = (0, exports.getQueueNameFromUrl)(queueUrl);
|
|
151
143
|
if (!QueueName) {
|
|
152
144
|
throw new Error(`Unable to determine QueueName from ${queueUrl}`);
|
|
153
145
|
}
|
|
146
|
+
const command = new client_sqs_1.GetQueueUrlCommand({ QueueName });
|
|
154
147
|
try {
|
|
155
|
-
await (0, services_1.sqs)().
|
|
148
|
+
await (0, services_1.sqs)().send(command);
|
|
156
149
|
return true;
|
|
157
150
|
}
|
|
158
151
|
catch (error) {
|
package/STS.d.ts
ADDED
package/STS.js
ADDED
package/SecretsManager.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getSecretString = void 0;
|
|
7
7
|
const services_1 = require("./services");
|
|
8
|
-
const getSecretString = (SecretId) => (0, services_1.secretsManager)().getSecretValue({ SecretId })
|
|
8
|
+
const getSecretString = async (SecretId) => (0, services_1.secretsManager)().getSecretValue({ SecretId })
|
|
9
9
|
.then((response) => response.SecretString);
|
|
10
10
|
exports.getSecretString = getSecretString;
|
|
11
11
|
//# sourceMappingURL=SecretsManager.js.map
|
package/StepFunctions.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module StepFunctions
|
|
3
3
|
*/
|
|
4
|
+
import { DescribeExecutionInput, DescribeExecutionOutput, DescribeStateMachineInput, DescribeStateMachineOutput, GetExecutionHistoryInput, HistoryEvent, ListExecutionsCommandInput } from '@aws-sdk/client-sfn';
|
|
5
|
+
export { HistoryEvent, DescribeExecutionOutput } from '@aws-sdk/client-sfn';
|
|
4
6
|
export declare const doesExecutionExist: (describeExecutionPromise: Promise<unknown>) => Promise<boolean>;
|
|
5
7
|
/**
|
|
6
8
|
* Call StepFunctions DescribeExecution
|
|
@@ -11,12 +13,12 @@ export declare const doesExecutionExist: (describeExecutionPromise: Promise<unkn
|
|
|
11
13
|
* If a ThrottlingException is received, this function will retry using an
|
|
12
14
|
* exponential backoff.
|
|
13
15
|
*
|
|
14
|
-
* @param {
|
|
15
|
-
* @returns {Promise<
|
|
16
|
+
* @param {DescribeExecutionInput} params
|
|
17
|
+
* @returns {Promise<DescribeExecutionOutput>}
|
|
16
18
|
*
|
|
17
19
|
* @kind function
|
|
18
20
|
*/
|
|
19
|
-
export declare const describeExecution: (params:
|
|
21
|
+
export declare const describeExecution: (params: DescribeExecutionInput) => Promise<DescribeExecutionOutput>;
|
|
20
22
|
/**
|
|
21
23
|
* Call StepFunctions DescribeStateMachine
|
|
22
24
|
*
|
|
@@ -26,12 +28,12 @@ export declare const describeExecution: (params: import("aws-sdk/clients/stepfun
|
|
|
26
28
|
* If a ThrottlingException is received, this function will retry using an
|
|
27
29
|
* exponential backoff.
|
|
28
30
|
*
|
|
29
|
-
* @param {
|
|
30
|
-
* @returns {Promise<
|
|
31
|
+
* @param {DescribeStateMachineInput} params
|
|
32
|
+
* @returns {Promise<DescribeStateMachineOutput>}
|
|
31
33
|
*
|
|
32
34
|
* @kind function
|
|
33
35
|
*/
|
|
34
|
-
export declare const describeStateMachine: (params:
|
|
36
|
+
export declare const describeStateMachine: (params: DescribeStateMachineInput) => Promise<DescribeStateMachineOutput>;
|
|
35
37
|
/**
|
|
36
38
|
* Check if a Step Function Execution exists
|
|
37
39
|
*
|
|
@@ -54,24 +56,22 @@ export declare const executionExists: (executionArn: string) => Promise<boolean>
|
|
|
54
56
|
* If a ThrottlingException is received, this function will retry using an
|
|
55
57
|
* exponential backoff.
|
|
56
58
|
*
|
|
57
|
-
* @param {
|
|
58
|
-
* @returns {Promise<
|
|
59
|
+
* @param {GetExecutionHistoryInput} params
|
|
60
|
+
* @returns {Promise<GetExecutionHistoryOutput>}
|
|
59
61
|
*
|
|
60
62
|
* @kind function
|
|
61
63
|
*/
|
|
62
|
-
export declare const getExecutionHistory: (params:
|
|
63
|
-
events:
|
|
64
|
+
export declare const getExecutionHistory: (params: GetExecutionHistoryInput, previousResponse?: {
|
|
65
|
+
events: HistoryEvent[];
|
|
64
66
|
} | undefined) => Promise<{
|
|
65
|
-
events:
|
|
67
|
+
events: HistoryEvent[];
|
|
66
68
|
}>;
|
|
67
69
|
export declare const getExecutionStatus: (executionArn: string) => Promise<{
|
|
68
|
-
execution:
|
|
69
|
-
$response: import("aws-sdk").Response<import("aws-sdk/clients/stepfunctions").DescribeExecutionOutput, import("aws-sdk").AWSError>;
|
|
70
|
-
};
|
|
70
|
+
execution: DescribeExecutionOutput;
|
|
71
71
|
executionHistory: {
|
|
72
|
-
events:
|
|
72
|
+
events: HistoryEvent[];
|
|
73
73
|
};
|
|
74
|
-
stateMachine:
|
|
74
|
+
stateMachine: DescribeStateMachineOutput;
|
|
75
75
|
}>;
|
|
76
76
|
/**
|
|
77
77
|
* Call StepFunctions ListExecutions
|
|
@@ -87,5 +87,5 @@ export declare const getExecutionStatus: (executionArn: string) => Promise<{
|
|
|
87
87
|
*
|
|
88
88
|
* @kind function
|
|
89
89
|
*/
|
|
90
|
-
export declare const listExecutions: (params:
|
|
90
|
+
export declare const listExecutions: (params: ListExecutionsCommandInput) => Promise<import("@aws-sdk/client-sfn").ListExecutionsCommandOutput>;
|
|
91
91
|
//# sourceMappingURL=StepFunctions.d.ts.map
|