@cumulus/aws-client 11.0.0 → 11.1.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/DynamoDb.d.ts +27 -24
- package/DynamoDb.js +31 -19
- package/DynamoDbSearchQueue.js +10 -5
- package/README.md +168 -159
- package/S3.d.ts +86 -94
- package/S3.js +176 -135
- package/S3ListObjectsV2Queue.d.ts +4 -3
- package/S3ListObjectsV2Queue.js +1 -1
- package/S3ObjectStore.d.ts +12 -9
- package/S3ObjectStore.js +43 -44
- package/client.d.ts +2 -2
- package/client.js +13 -14
- package/lib/S3MultipartUploads.d.ts +5 -4
- package/lib/S3MultipartUploads.js +4 -4
- package/package.json +20 -7
- package/services.d.ts +25 -21
- package/services.js +30 -22
- package/test-utils.d.ts +26 -4
- package/test-utils.js +24 -17
- package/types.d.ts +6 -0
- package/types.js +3 -0
- package/utils.d.ts +1 -0
- package/utils.js +3 -1
package/DynamoDb.d.ts
CHANGED
|
@@ -2,31 +2,34 @@
|
|
|
2
2
|
* @module DynamoDb
|
|
3
3
|
*/
|
|
4
4
|
import pRetry from 'p-retry';
|
|
5
|
-
import {
|
|
5
|
+
import { CreateTableInput, DeleteTableInput, ScanInput } from '@aws-sdk/client-dynamodb';
|
|
6
|
+
import { DynamoDBDocument, GetCommandInput, ScanCommandInput, ScanCommandOutput } from '@aws-sdk/lib-dynamodb';
|
|
6
7
|
/**
|
|
7
8
|
* Call DynamoDb client get
|
|
8
9
|
*
|
|
9
|
-
* See [DocumentClient.get()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
10
|
+
* See [DocumentClient.get()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
|
|
10
11
|
* for descriptions of `params` and the return data.
|
|
11
12
|
*
|
|
12
13
|
* @param {Object} params
|
|
13
14
|
* @param {string} params.tableName - Table name to read
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {GetCommandInput.Key} params.item - Key identifying object to get
|
|
16
|
+
* @param {DynamoDBDocument} params.client - Instance of a DynamoDb DocumentClient
|
|
16
17
|
* @param {Object} params.getParams - Additional parameters for DocumentClient.get()
|
|
17
18
|
* @returns {Promise<Object>}
|
|
18
19
|
* @throws {RecordDoesNotExist} if a record cannot be found
|
|
19
20
|
*/
|
|
20
21
|
export declare const get: (params: {
|
|
21
22
|
tableName: string;
|
|
22
|
-
item:
|
|
23
|
-
client:
|
|
24
|
-
getParams?: object
|
|
25
|
-
}) => Promise<
|
|
23
|
+
item: GetCommandInput['Key'];
|
|
24
|
+
client: DynamoDBDocument;
|
|
25
|
+
getParams?: object;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}>;
|
|
26
29
|
/**
|
|
27
30
|
* Call DynamoDb client scan
|
|
28
31
|
*
|
|
29
|
-
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
32
|
+
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
|
|
30
33
|
* for descriptions of `params` and the return data.
|
|
31
34
|
*
|
|
32
35
|
* @param {Object} params
|
|
@@ -34,59 +37,59 @@ export declare const get: (params: {
|
|
|
34
37
|
*/
|
|
35
38
|
export declare const scan: (params: {
|
|
36
39
|
tableName: string;
|
|
37
|
-
client:
|
|
40
|
+
client: DynamoDBDocument;
|
|
38
41
|
query?: {
|
|
39
42
|
filter?: string | undefined;
|
|
40
|
-
names?:
|
|
41
|
-
values?:
|
|
43
|
+
names?: ScanInput['ExpressionAttributeNames'];
|
|
44
|
+
values?: ScanCommandInput['ExpressionAttributeValues'];
|
|
42
45
|
} | undefined;
|
|
43
46
|
fields?: string | undefined;
|
|
44
47
|
limit?: number | undefined;
|
|
45
48
|
select: string;
|
|
46
|
-
startKey?:
|
|
47
|
-
}) => Promise<
|
|
49
|
+
startKey?: ScanInput['ExclusiveStartKey'];
|
|
50
|
+
}) => Promise<ScanCommandOutput>;
|
|
48
51
|
/**
|
|
49
52
|
* Do a parallel scan of DynamoDB table using a document client.
|
|
50
53
|
*
|
|
51
54
|
* See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.ParallelScan.
|
|
52
|
-
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
55
|
+
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html).
|
|
53
56
|
*
|
|
54
57
|
* @param {Object} params
|
|
55
58
|
* @param {number} params.totalSegments
|
|
56
59
|
* Total number of segments to divide table into for parallel scanning
|
|
57
|
-
* @param {
|
|
60
|
+
* @param {ScanInput} params.scanParams
|
|
58
61
|
* Params for the DynamoDB client scan operation
|
|
59
62
|
* See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
|
|
60
63
|
* @param {function} params.processItemsFunc - Function used to process returned items by scan
|
|
61
|
-
* @param {
|
|
64
|
+
* @param {DynamoDBDocument} [params.dynamoDbClient] - Instance of Dynamo DB document client
|
|
62
65
|
* @param {pRetry.Options} [params.retryOptions] - Retry options for scan operations
|
|
63
66
|
* @returns {Promise}
|
|
64
67
|
*/
|
|
65
68
|
export declare const parallelScan: (params: {
|
|
66
69
|
totalSegments: number;
|
|
67
|
-
scanParams:
|
|
68
|
-
processItemsFunc: (items:
|
|
69
|
-
dynamoDbClient
|
|
70
|
+
scanParams: ScanCommandInput;
|
|
71
|
+
processItemsFunc: (items: ScanCommandOutput['Items']) => Promise<void>;
|
|
72
|
+
dynamoDbClient: DynamoDBDocument;
|
|
70
73
|
retryOptions?: pRetry.Options | undefined;
|
|
71
74
|
}) => Promise<void[]>;
|
|
72
75
|
/**
|
|
73
76
|
* Create a DynamoDB table and then wait for the table to exist
|
|
74
77
|
*
|
|
75
78
|
* @param {Object} params - the same params that you would pass to AWS.createTable
|
|
76
|
-
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
79
|
+
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/dynamodb.html#createtable
|
|
77
80
|
* @returns {Promise<Object>} the output of the createTable call
|
|
78
81
|
*
|
|
79
82
|
* @static
|
|
80
83
|
*/
|
|
81
|
-
export declare function createAndWaitForDynamoDbTable(params:
|
|
84
|
+
export declare function createAndWaitForDynamoDbTable(params: CreateTableInput): Promise<import("@aws-sdk/client-dynamodb").CreateTableCommandOutput>;
|
|
82
85
|
/**
|
|
83
86
|
* Delete a DynamoDB table and then wait for the table to not exist
|
|
84
87
|
*
|
|
85
88
|
* @param {Object} params - the same params that you would pass to AWS.deleteTable
|
|
86
|
-
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
89
|
+
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/dynamodb.html#deletetable
|
|
87
90
|
* @returns {Promise}
|
|
88
91
|
*
|
|
89
92
|
* @static
|
|
90
93
|
*/
|
|
91
|
-
export declare function deleteAndWaitForDynamoDbTableNotExists(params:
|
|
94
|
+
export declare function deleteAndWaitForDynamoDbTableNotExists(params: DeleteTableInput): Promise<void>;
|
|
92
95
|
//# sourceMappingURL=DynamoDb.d.ts.map
|
package/DynamoDb.js
CHANGED
|
@@ -10,38 +10,40 @@ exports.deleteAndWaitForDynamoDbTableNotExists = exports.createAndWaitForDynamoD
|
|
|
10
10
|
const p_map_1 = __importDefault(require("p-map"));
|
|
11
11
|
const p_retry_1 = __importDefault(require("p-retry"));
|
|
12
12
|
const range_1 = __importDefault(require("lodash/range"));
|
|
13
|
+
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
13
14
|
const errors_1 = require("@cumulus/errors");
|
|
14
15
|
const services_1 = require("./services");
|
|
15
16
|
const utils_1 = require("./utils");
|
|
16
17
|
/**
|
|
17
18
|
* Call DynamoDb client get
|
|
18
19
|
*
|
|
19
|
-
* See [DocumentClient.get()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
20
|
+
* See [DocumentClient.get()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
|
|
20
21
|
* for descriptions of `params` and the return data.
|
|
21
22
|
*
|
|
22
23
|
* @param {Object} params
|
|
23
24
|
* @param {string} params.tableName - Table name to read
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {GetCommandInput.Key} params.item - Key identifying object to get
|
|
26
|
+
* @param {DynamoDBDocument} params.client - Instance of a DynamoDb DocumentClient
|
|
26
27
|
* @param {Object} params.getParams - Additional parameters for DocumentClient.get()
|
|
27
28
|
* @returns {Promise<Object>}
|
|
28
29
|
* @throws {RecordDoesNotExist} if a record cannot be found
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
const get = async (params) => {
|
|
31
32
|
const { client, getParams = {}, item, tableName, } = params;
|
|
32
33
|
const getResponse = await client.get({
|
|
33
34
|
...getParams,
|
|
34
35
|
TableName: tableName,
|
|
35
36
|
Key: item,
|
|
36
|
-
})
|
|
37
|
+
});
|
|
37
38
|
if (getResponse.Item)
|
|
38
39
|
return getResponse.Item;
|
|
39
40
|
throw new errors_1.RecordDoesNotExist(`No record found for ${JSON.stringify(item)} in ${tableName}`);
|
|
40
|
-
}
|
|
41
|
+
};
|
|
42
|
+
exports.get = get;
|
|
41
43
|
/**
|
|
42
44
|
* Call DynamoDb client scan
|
|
43
45
|
*
|
|
44
|
-
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
46
|
+
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html)
|
|
45
47
|
* for descriptions of `params` and the return data.
|
|
46
48
|
*
|
|
47
49
|
* @param {Object} params
|
|
@@ -73,7 +75,7 @@ exports.scan = (0, utils_1.improveStackTrace)(async (params) => {
|
|
|
73
75
|
if (startKey) {
|
|
74
76
|
scanParams.ExclusiveStartKey = startKey;
|
|
75
77
|
}
|
|
76
|
-
const response = await client.scan(scanParams)
|
|
78
|
+
const response = await client.scan(scanParams);
|
|
77
79
|
// recursively go through all the records
|
|
78
80
|
if (response.LastEvaluatedKey) {
|
|
79
81
|
const more = await (0, exports.scan)({
|
|
@@ -98,21 +100,21 @@ exports.scan = (0, utils_1.improveStackTrace)(async (params) => {
|
|
|
98
100
|
* Do a parallel scan of DynamoDB table using a document client.
|
|
99
101
|
*
|
|
100
102
|
* See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.ParallelScan.
|
|
101
|
-
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
103
|
+
* See [DocumentClient.scan()](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html).
|
|
102
104
|
*
|
|
103
105
|
* @param {Object} params
|
|
104
106
|
* @param {number} params.totalSegments
|
|
105
107
|
* Total number of segments to divide table into for parallel scanning
|
|
106
|
-
* @param {
|
|
108
|
+
* @param {ScanInput} params.scanParams
|
|
107
109
|
* Params for the DynamoDB client scan operation
|
|
108
110
|
* See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html
|
|
109
111
|
* @param {function} params.processItemsFunc - Function used to process returned items by scan
|
|
110
|
-
* @param {
|
|
112
|
+
* @param {DynamoDBDocument} [params.dynamoDbClient] - Instance of Dynamo DB document client
|
|
111
113
|
* @param {pRetry.Options} [params.retryOptions] - Retry options for scan operations
|
|
112
114
|
* @returns {Promise}
|
|
113
115
|
*/
|
|
114
116
|
const parallelScan = async (params) => {
|
|
115
|
-
const { totalSegments, scanParams, processItemsFunc, dynamoDbClient
|
|
117
|
+
const { totalSegments, scanParams, processItemsFunc, dynamoDbClient, retryOptions, } = params;
|
|
116
118
|
return await (0, p_map_1.default)((0, range_1.default)(totalSegments), async (_, segmentIndex) => {
|
|
117
119
|
let exclusiveStartKey;
|
|
118
120
|
const segmentScanParams = {
|
|
@@ -122,7 +124,7 @@ const parallelScan = async (params) => {
|
|
|
122
124
|
};
|
|
123
125
|
/* eslint-disable no-await-in-loop */
|
|
124
126
|
do {
|
|
125
|
-
const { Items = [], LastEvaluatedKey, } = await (0, p_retry_1.default)(() => dynamoDbClient.scan(segmentScanParams)
|
|
127
|
+
const { Items = [], LastEvaluatedKey, } = await (0, p_retry_1.default)(() => dynamoDbClient.scan(segmentScanParams), retryOptions);
|
|
126
128
|
exclusiveStartKey = LastEvaluatedKey;
|
|
127
129
|
segmentScanParams.ExclusiveStartKey = exclusiveStartKey;
|
|
128
130
|
await processItemsFunc(Items);
|
|
@@ -138,14 +140,19 @@ exports.parallelScan = parallelScan;
|
|
|
138
140
|
* Create a DynamoDB table and then wait for the table to exist
|
|
139
141
|
*
|
|
140
142
|
* @param {Object} params - the same params that you would pass to AWS.createTable
|
|
141
|
-
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
143
|
+
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/dynamodb.html#createtable
|
|
142
144
|
* @returns {Promise<Object>} the output of the createTable call
|
|
143
145
|
*
|
|
144
146
|
* @static
|
|
145
147
|
*/
|
|
146
148
|
async function createAndWaitForDynamoDbTable(params) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
+
const dynamoDbClient = (0, services_1.dynamodb)();
|
|
150
|
+
const createTableResult = await dynamoDbClient.createTable(params);
|
|
151
|
+
await (0, client_dynamodb_1.waitUntilTableExists)({
|
|
152
|
+
client: dynamoDbClient,
|
|
153
|
+
minDelay: 1,
|
|
154
|
+
maxWaitTime: 3,
|
|
155
|
+
}, { TableName: params.TableName });
|
|
149
156
|
return createTableResult;
|
|
150
157
|
}
|
|
151
158
|
exports.createAndWaitForDynamoDbTable = createAndWaitForDynamoDbTable;
|
|
@@ -153,14 +160,19 @@ exports.createAndWaitForDynamoDbTable = createAndWaitForDynamoDbTable;
|
|
|
153
160
|
* Delete a DynamoDB table and then wait for the table to not exist
|
|
154
161
|
*
|
|
155
162
|
* @param {Object} params - the same params that you would pass to AWS.deleteTable
|
|
156
|
-
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/
|
|
163
|
+
* See https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/dynamodb.html#deletetable
|
|
157
164
|
* @returns {Promise}
|
|
158
165
|
*
|
|
159
166
|
* @static
|
|
160
167
|
*/
|
|
161
168
|
async function deleteAndWaitForDynamoDbTableNotExists(params) {
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
const dynamoDbClient = (0, services_1.dynamodb)();
|
|
170
|
+
await dynamoDbClient.deleteTable(params);
|
|
171
|
+
await (0, client_dynamodb_1.waitUntilTableNotExists)({
|
|
172
|
+
client: dynamoDbClient,
|
|
173
|
+
minDelay: 1,
|
|
174
|
+
maxWaitTime: 3,
|
|
175
|
+
}, { TableName: params.TableName });
|
|
164
176
|
}
|
|
165
177
|
exports.deleteAndWaitForDynamoDbTableNotExists = deleteAndWaitForDynamoDbTableNotExists;
|
|
166
178
|
//# sourceMappingURL=DynamoDb.js.map
|
package/DynamoDbSearchQueue.js
CHANGED
|
@@ -83,12 +83,17 @@ class DynamoDbSearchQueue {
|
|
|
83
83
|
async fetchItems() {
|
|
84
84
|
let response;
|
|
85
85
|
do {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
if (this.searchType === 'scan') {
|
|
87
|
+
response = await this.dynamodbDocClient.scan(this.params); // eslint-disable-line no-await-in-loop, max-len
|
|
88
|
+
}
|
|
89
|
+
else if (this.searchType === 'query') {
|
|
90
|
+
response = await this.dynamodbDocClient.query(this.params); // eslint-disable-line no-await-in-loop, max-len
|
|
91
|
+
}
|
|
92
|
+
if (response === null || response === void 0 ? void 0 : response.LastEvaluatedKey)
|
|
88
93
|
this.params.ExclusiveStartKey = response.LastEvaluatedKey;
|
|
89
|
-
} while ((response.Items || []).length === 0 && response.LastEvaluatedKey);
|
|
90
|
-
this.items = (response.Items || []);
|
|
91
|
-
if (!response.LastEvaluatedKey)
|
|
94
|
+
} while (((response === null || response === void 0 ? void 0 : response.Items) || []).length === 0 && (response === null || response === void 0 ? void 0 : response.LastEvaluatedKey));
|
|
95
|
+
this.items = ((response === null || response === void 0 ? void 0 : response.Items) || []);
|
|
96
|
+
if (!(response === null || response === void 0 ? void 0 : response.LastEvaluatedKey))
|
|
92
97
|
this.items.push(null);
|
|
93
98
|
}
|
|
94
99
|
}
|