@cumulus/aws-client 11.1.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/README.md +139 -130
- 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.js +0 -4
- package/lib/S3MultipartUploads.d.ts +5 -4
- package/lib/S3MultipartUploads.js +4 -4
- package/package.json +14 -6
- package/services.d.ts +2 -1
- package/services.js +2 -1
- package/test-utils.d.ts +7 -3
- package/test-utils.js +6 -5
- package/types.d.ts +2 -1
package/S3ObjectStore.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
|
-
const querystring = __importStar(require("querystring"));
|
|
29
5
|
const url_1 = require("url");
|
|
30
|
-
const
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
8
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
31
9
|
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
32
10
|
const S3_1 = require("./S3");
|
|
33
11
|
const client_1 = __importDefault(require("./client"));
|
|
@@ -38,8 +16,35 @@ const log = new logger_1.default({ sender: '@cumulus/aws-client/S3ObjectStore' }
|
|
|
38
16
|
*
|
|
39
17
|
*/
|
|
40
18
|
class S3ObjectStore {
|
|
41
|
-
constructor() {
|
|
42
|
-
this.s3 = (0, client_1.default)(
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.s3 = (0, client_1.default)(client_s3_1.S3, '2006-03-01', {
|
|
21
|
+
signatureVersion: 'v4',
|
|
22
|
+
})(config);
|
|
23
|
+
this.queryParams = {};
|
|
24
|
+
this.middlewareName = `customQueryParams${(0, uuid_1.v4)()}`;
|
|
25
|
+
}
|
|
26
|
+
getQueryParams() {
|
|
27
|
+
return this.queryParams;
|
|
28
|
+
}
|
|
29
|
+
setQueryParams(queryParams) {
|
|
30
|
+
this.queryParams = queryParams;
|
|
31
|
+
}
|
|
32
|
+
async getS3SignedUrlWithCustomQueryParams(command) {
|
|
33
|
+
this.s3.middlewareStack.addRelativeTo((next) => (args) => {
|
|
34
|
+
const { request } = args;
|
|
35
|
+
request.query = {
|
|
36
|
+
...this.getQueryParams(),
|
|
37
|
+
...request.query,
|
|
38
|
+
};
|
|
39
|
+
return next(args);
|
|
40
|
+
}, {
|
|
41
|
+
name: this.middlewareName,
|
|
42
|
+
relation: 'before',
|
|
43
|
+
toMiddleware: 'presignInterceptMiddleware',
|
|
44
|
+
});
|
|
45
|
+
const signedUrl = await (0, s3_request_presigner_1.getSignedUrl)(this.s3, command);
|
|
46
|
+
this.s3.middlewareStack.remove(this.middlewareName);
|
|
47
|
+
return signedUrl;
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
50
|
* Returns an HTTPS URL that can be used to perform a GET on the given object
|
|
@@ -51,7 +56,7 @@ class S3ObjectStore {
|
|
|
51
56
|
* @returns {Promise<string>} a signed URL
|
|
52
57
|
* @throws TypeError - if the URL is not a recognized protocol or cannot be parsed
|
|
53
58
|
*/
|
|
54
|
-
async signGetObject(objectUrl, options = {}, queryParams) {
|
|
59
|
+
async signGetObject(objectUrl, options = {}, queryParams = {}) {
|
|
55
60
|
log.info(`Executing signGetObject with objectUrl: ${objectUrl}, options: ${JSON.stringify(options)}, queryParams: ${JSON.stringify(queryParams)}`);
|
|
56
61
|
const url = new url_1.URL(objectUrl);
|
|
57
62
|
if (url.protocol.toLowerCase() !== 's3:') {
|
|
@@ -59,14 +64,11 @@ class S3ObjectStore {
|
|
|
59
64
|
}
|
|
60
65
|
const { Bucket, Key } = (0, S3_1.parseS3Uri)(objectUrl);
|
|
61
66
|
await (0, S3_1.headObject)(Bucket, Key);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const result = await req.presign();
|
|
68
|
-
log.debug(`Signed GetObject request URL: ${result}`);
|
|
69
|
-
return result;
|
|
67
|
+
const command = new client_s3_1.GetObjectCommand({ Bucket, Key, ...options });
|
|
68
|
+
this.setQueryParams(queryParams);
|
|
69
|
+
const signedUrl = await this.getS3SignedUrlWithCustomQueryParams(command);
|
|
70
|
+
log.debug(`Signed GetObject request URL: ${signedUrl}`);
|
|
71
|
+
return signedUrl;
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* Returns an HTTPS URL that can be used to perform a HEAD on the given object
|
|
@@ -85,14 +87,11 @@ class S3ObjectStore {
|
|
|
85
87
|
throw new TypeError(`Invalid S3 URL: ${objectUrl}`);
|
|
86
88
|
}
|
|
87
89
|
const { Bucket, Key } = (0, S3_1.parseS3Uri)(objectUrl);
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const result = await req.presign();
|
|
94
|
-
log.debug(`Signed HeadObject request URL: ${result}`);
|
|
95
|
-
return result;
|
|
90
|
+
const command = new client_s3_1.HeadObjectCommand({ Bucket, Key, ...options });
|
|
91
|
+
this.setQueryParams(queryParams);
|
|
92
|
+
const signedUrl = await this.getS3SignedUrlWithCustomQueryParams(command);
|
|
93
|
+
log.debug(`Signed HeadObject request URL: ${signedUrl}`);
|
|
94
|
+
return signedUrl;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
module.exports = S3ObjectStore;
|
package/client.js
CHANGED
|
@@ -6,11 +6,7 @@ const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
|
6
6
|
const mem_1 = __importDefault(require("mem"));
|
|
7
7
|
const test_utils_1 = require("./test-utils");
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
-
const noop = () => { }; // eslint-disable-line lodash/prefer-noop
|
|
10
9
|
const getRegion = () => process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || 'us-east-1';
|
|
11
|
-
// Workaround upload hangs. See: https://github.com/andrewrk/node-s3-client/issues/74
|
|
12
|
-
// @ts-ignore - AWS.util is not part of the public API and may break
|
|
13
|
-
aws_sdk_1.default.util.update(aws_sdk_1.default.S3.prototype, { addExpect100Continue: noop });
|
|
14
10
|
aws_sdk_1.default.config.setPromisesDependency(Promise);
|
|
15
11
|
const buildServiceClient = (Service, options) => {
|
|
16
12
|
if ((0, test_utils_1.inTestMode)()) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AbortMultipartUploadRequest, CompleteMultipartUploadRequest, CreateMultipartUploadRequest, UploadPartCopyRequest } from '@aws-sdk/client-s3';
|
|
1
2
|
export interface CompleteMultipartUploadOutput extends AWS.S3.CompleteMultipartUploadOutput {
|
|
2
3
|
ETag: string;
|
|
3
4
|
}
|
|
@@ -23,9 +24,9 @@ declare type Chunk = {
|
|
|
23
24
|
* @returns {Promise<Array<Chunk>>} - array of chunks
|
|
24
25
|
*/
|
|
25
26
|
export declare const createMultipartChunks: (objectSize: number, chunkSize?: number) => Chunk[];
|
|
26
|
-
export declare const createMultipartUpload: (params:
|
|
27
|
-
export declare const completeMultipartUpload: (params:
|
|
28
|
-
export declare const abortMultipartUpload: (params:
|
|
29
|
-
export declare const uploadPartCopy: (params:
|
|
27
|
+
export declare const createMultipartUpload: (params: CreateMultipartUploadRequest) => Promise<import("@aws-sdk/client-s3").CreateMultipartUploadCommandOutput>;
|
|
28
|
+
export declare const completeMultipartUpload: (params: CompleteMultipartUploadRequest) => Promise<CompleteMultipartUploadOutput>;
|
|
29
|
+
export declare const abortMultipartUpload: (params: AbortMultipartUploadRequest) => Promise<import("@aws-sdk/client-s3").AbortMultipartUploadCommandOutput>;
|
|
30
|
+
export declare const uploadPartCopy: (params: UploadPartCopyRequest) => Promise<import("@aws-sdk/client-s3").UploadPartCopyCommandOutput>;
|
|
30
31
|
export {};
|
|
31
32
|
//# sourceMappingURL=S3MultipartUploads.d.ts.map
|
|
@@ -31,15 +31,15 @@ const createMultipartChunks = (objectSize, chunkSize = 250 * MB) => (0, range_1.
|
|
|
31
31
|
end: Math.min(start + chunkSize, objectSize) - 1,
|
|
32
32
|
}));
|
|
33
33
|
exports.createMultipartChunks = createMultipartChunks;
|
|
34
|
-
const createMultipartUpload = async (params) => await (0, services_1.s3)().createMultipartUpload(params)
|
|
34
|
+
const createMultipartUpload = async (params) => await (0, services_1.s3)().createMultipartUpload(params);
|
|
35
35
|
exports.createMultipartUpload = createMultipartUpload;
|
|
36
36
|
const completeMultipartUpload = async (params) => {
|
|
37
|
-
const result = await (0, services_1.s3)().completeMultipartUpload(params)
|
|
37
|
+
const result = await (0, services_1.s3)().completeMultipartUpload(params);
|
|
38
38
|
return result;
|
|
39
39
|
};
|
|
40
40
|
exports.completeMultipartUpload = completeMultipartUpload;
|
|
41
|
-
const abortMultipartUpload = async (params) => await (0, services_1.s3)().abortMultipartUpload(params)
|
|
41
|
+
const abortMultipartUpload = async (params) => await (0, services_1.s3)().abortMultipartUpload(params);
|
|
42
42
|
exports.abortMultipartUpload = abortMultipartUpload;
|
|
43
|
-
const uploadPartCopy = async (params) => await (0, services_1.s3)().uploadPartCopy(params)
|
|
43
|
+
const uploadPartCopy = async (params) => await (0, services_1.s3)().uploadPartCopy(params);
|
|
44
44
|
exports.uploadPartCopy = uploadPartCopy;
|
|
45
45
|
//# sourceMappingURL=S3MultipartUploads.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/aws-client",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.1",
|
|
4
4
|
"description": "Utilities for working with AWS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"GIBS",
|
|
@@ -45,11 +45,15 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@aws-sdk/client-dynamodb": "^3.53.0",
|
|
47
47
|
"@aws-sdk/client-dynamodb-streams": "^3.53.0",
|
|
48
|
+
"@aws-sdk/client-s3": "^3.53.0",
|
|
48
49
|
"@aws-sdk/lib-dynamodb": "^3.53.0",
|
|
50
|
+
"@aws-sdk/lib-storage": "^3.53.0",
|
|
51
|
+
"@aws-sdk/s3-request-presigner": "^3.53.0",
|
|
52
|
+
"@aws-sdk/signature-v4-crt": "^3.53.0",
|
|
49
53
|
"@aws-sdk/types": "^3.53.0",
|
|
50
|
-
"@cumulus/checksum": "11.1.
|
|
51
|
-
"@cumulus/errors": "11.1.
|
|
52
|
-
"@cumulus/logger": "11.1.
|
|
54
|
+
"@cumulus/checksum": "11.1.1",
|
|
55
|
+
"@cumulus/errors": "11.1.1",
|
|
56
|
+
"@cumulus/logger": "11.1.1",
|
|
53
57
|
"aws-sdk": "^2.585.0",
|
|
54
58
|
"jsonpath-plus": "^1.1.0",
|
|
55
59
|
"lodash": "~4.17.21",
|
|
@@ -58,7 +62,11 @@
|
|
|
58
62
|
"p-retry": "^4.2.0",
|
|
59
63
|
"p-timeout": "^4.1.0",
|
|
60
64
|
"p-wait-for": "^3.2.0",
|
|
61
|
-
"pump": "^3.0.0"
|
|
65
|
+
"pump": "^3.0.0",
|
|
66
|
+
"uuid": "^8.2.0"
|
|
62
67
|
},
|
|
63
|
-
"
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/uuid": "^8.0.0"
|
|
70
|
+
},
|
|
71
|
+
"gitHead": "07fe682da23821434372759fb1948b081da429b5"
|
|
64
72
|
}
|
package/services.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DynamoDB } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { DynamoDBStreamsClient } from '@aws-sdk/client-dynamodb-streams';
|
|
3
|
+
import { S3 } from '@aws-sdk/client-s3';
|
|
3
4
|
import { DynamoDBDocument, TranslateConfig } from '@aws-sdk/lib-dynamodb';
|
|
4
5
|
import * as AWS from 'aws-sdk';
|
|
5
6
|
export declare const apigateway: (params?: object | undefined) => AWS.APIGateway;
|
|
6
7
|
export declare const ecs: (params?: object | undefined) => AWS.ECS;
|
|
7
8
|
export declare const ec2: (params?: object | undefined) => AWS.EC2;
|
|
8
|
-
export declare const s3: (params?: object | undefined) =>
|
|
9
|
+
export declare const s3: (params?: object | undefined) => S3;
|
|
9
10
|
export declare const kinesis: (params?: object | undefined) => AWS.Kinesis;
|
|
10
11
|
export declare const lambda: (params?: object | undefined) => AWS.Lambda;
|
|
11
12
|
export declare const sqs: (params?: object | undefined) => AWS.SQS;
|
package/services.js
CHANGED
|
@@ -29,13 +29,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.sts = exports.es = exports.kms = exports.systemsManager = exports.secretsManager = exports.sns = exports.cf = exports.sfn = exports.dynamodbDocClient = exports.dynamodbstreams = exports.dynamodb = exports.cloudwatch = exports.cloudwatchlogs = exports.cloudwatchevents = exports.sqs = exports.lambda = exports.kinesis = exports.s3 = exports.ec2 = exports.ecs = exports.apigateway = void 0;
|
|
30
30
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
31
31
|
const client_dynamodb_streams_1 = require("@aws-sdk/client-dynamodb-streams");
|
|
32
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
32
33
|
const lib_dynamodb_1 = require("@aws-sdk/lib-dynamodb");
|
|
33
34
|
const AWS = __importStar(require("aws-sdk"));
|
|
34
35
|
const client_1 = __importDefault(require("./client"));
|
|
35
36
|
exports.apigateway = (0, client_1.default)(AWS.APIGateway, '2015-07-09');
|
|
36
37
|
exports.ecs = (0, client_1.default)(AWS.ECS, '2014-11-13');
|
|
37
38
|
exports.ec2 = (0, client_1.default)(AWS.EC2, '2016-11-15');
|
|
38
|
-
exports.s3 = (0, client_1.default)(
|
|
39
|
+
exports.s3 = (0, client_1.default)(client_s3_1.S3, '2006-03-01');
|
|
39
40
|
exports.kinesis = (0, client_1.default)(AWS.Kinesis, '2013-12-02');
|
|
40
41
|
exports.lambda = (0, client_1.default)(AWS.Lambda, '2015-03-31');
|
|
41
42
|
exports.sqs = (0, client_1.default)(AWS.SQS, '2012-11-05');
|
package/test-utils.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare const localStackPorts: {
|
|
|
20
20
|
lambda: number;
|
|
21
21
|
redshift: number;
|
|
22
22
|
route53: number;
|
|
23
|
-
|
|
23
|
+
S3: number;
|
|
24
24
|
secretsmanager: number;
|
|
25
25
|
ses: number;
|
|
26
26
|
sns: number;
|
|
@@ -48,7 +48,9 @@ export declare function getLocalstackEndpoint(identifier: keyof typeof localStac
|
|
|
48
48
|
*
|
|
49
49
|
* @private
|
|
50
50
|
*/
|
|
51
|
-
export declare function localStackAwsClientOptions<T>(Service: new (params: object) => T, options?:
|
|
51
|
+
export declare function localStackAwsClientOptions<T>(Service: new (params: object) => T, options?: {
|
|
52
|
+
credentials?: object;
|
|
53
|
+
}): {
|
|
52
54
|
[key: string]: unknown;
|
|
53
55
|
};
|
|
54
56
|
/**
|
|
@@ -60,7 +62,9 @@ export declare function localStackAwsClientOptions<T>(Service: new (params: obje
|
|
|
60
62
|
*
|
|
61
63
|
* @private
|
|
62
64
|
*/
|
|
63
|
-
export declare function getLocalstackAwsClientOptions<T extends AWSClientTypes>(Service: new (params: object) => T, options?:
|
|
65
|
+
export declare function getLocalstackAwsClientOptions<T extends AWSClientTypes>(Service: new (params: object) => T, options?: {
|
|
66
|
+
credentials?: object;
|
|
67
|
+
}): object;
|
|
64
68
|
/**
|
|
65
69
|
* Return a function that throws a ThrottlingException the first time it is called, then returns as
|
|
66
70
|
* normal any other times.
|
package/test-utils.js
CHANGED
|
@@ -26,7 +26,7 @@ const localStackPorts = {
|
|
|
26
26
|
lambda: 4566,
|
|
27
27
|
redshift: 4566,
|
|
28
28
|
route53: 4566,
|
|
29
|
-
|
|
29
|
+
S3: 4566,
|
|
30
30
|
secretsmanager: 4566,
|
|
31
31
|
ses: 4566,
|
|
32
32
|
sns: 4566,
|
|
@@ -79,16 +79,17 @@ function localStackAwsClientOptions(Service, options = {}) {
|
|
|
79
79
|
}
|
|
80
80
|
const serviceIdentifier = (0, utils_1.getServiceIdentifer)(Service);
|
|
81
81
|
const localStackOptions = {
|
|
82
|
+
region: 'us-east-1',
|
|
83
|
+
endpoint: getLocalstackEndpoint(serviceIdentifier),
|
|
82
84
|
...options,
|
|
83
85
|
credentials: {
|
|
84
86
|
accessKeyId: 'my-access-key-id',
|
|
85
87
|
secretAccessKey: 'my-secret-access-key',
|
|
88
|
+
...options.credentials,
|
|
86
89
|
},
|
|
87
|
-
region: 'us-east-1',
|
|
88
|
-
endpoint: getLocalstackEndpoint(serviceIdentifier),
|
|
89
90
|
};
|
|
90
91
|
if (serviceIdentifier.toLowerCase() === 's3')
|
|
91
|
-
localStackOptions.
|
|
92
|
+
localStackOptions.forcePathStyle = true;
|
|
92
93
|
return localStackOptions;
|
|
93
94
|
}
|
|
94
95
|
exports.localStackAwsClientOptions = localStackAwsClientOptions;
|
|
@@ -101,7 +102,7 @@ exports.localStackAwsClientOptions = localStackAwsClientOptions;
|
|
|
101
102
|
*
|
|
102
103
|
* @private
|
|
103
104
|
*/
|
|
104
|
-
function getLocalstackAwsClientOptions(Service, options) {
|
|
105
|
+
function getLocalstackAwsClientOptions(Service, options = {}) {
|
|
105
106
|
const serviceIdentifier = (0, utils_1.getServiceIdentifer)(Service);
|
|
106
107
|
if (localstackSupportedService(serviceIdentifier)) {
|
|
107
108
|
return localStackAwsClientOptions(Service, options);
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as AWS from 'aws-sdk';
|
|
2
2
|
import { DynamoDBStreamsClient } from '@aws-sdk/client-dynamodb-streams';
|
|
3
3
|
import { DynamoDB, DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
4
|
-
|
|
4
|
+
import { S3 } from '@aws-sdk/client-s3';
|
|
5
|
+
export declare type AWSClientTypes = DynamoDB | DynamoDBClient | DynamoDBStreamsClient | S3 | AWS.Service | AWS.DynamoDB.DocumentClient;
|
|
5
6
|
//# sourceMappingURL=types.d.ts.map
|