|
1 | 1 | const fs = require('fs'); |
2 | 2 | const { http, https } = require('httpagent'); |
3 | 3 |
|
4 | | -const AWS = require('aws-sdk'); |
| 4 | +const { S3Client } = require('@aws-sdk/client-s3'); |
| 5 | +const { NodeHttpHandler } = require('@aws-sdk/node-http-handler'); |
| 6 | +const { ConfiguredRetryStrategy } = require('@smithy/util-retry'); |
5 | 7 | const { doWhilst } = require('async'); |
6 | 8 |
|
7 | 9 | const { Logger } = require('werelogs'); |
@@ -97,38 +99,32 @@ if (s3EndpointIsHttps) { |
97 | 99 | agent = new http.Agent({ keepAlive: true }); |
98 | 100 | } |
99 | 101 |
|
100 | | -const options = { |
101 | | - accessKeyId: ACCESS_KEY, |
102 | | - secretAccessKey: SECRET_KEY, |
| 102 | +const s3 = new S3Client({ |
| 103 | + credentials: { |
| 104 | + accessKeyId: ACCESS_KEY, |
| 105 | + secretAccessKey: SECRET_KEY, |
| 106 | + }, |
103 | 107 | endpoint: ENDPOINT, |
104 | 108 | region: 'us-east-1', |
105 | | - sslEnabled: s3EndpointIsHttps, |
106 | | - s3ForcePathStyle: true, |
107 | | - apiVersions: { s3: '2006-03-01' }, |
108 | | - signatureVersion: 'v4', |
109 | | - signatureCache: false, |
110 | | - httpOptions: { |
111 | | - timeout: 0, |
112 | | - agent, |
113 | | - }, |
114 | | -}; |
115 | | -/** |
116 | | - * Options specific to s3 requests |
117 | | - * `maxRetries` & `customBackoff` are set only to s3 requests |
118 | | - * default aws sdk retry count is 3 with an exponential delay of 2^n * 30 ms |
119 | | - */ |
120 | | -const s3Options = { |
121 | | - maxRetries: AWS_SDK_REQUEST_RETRIES, |
122 | | - customBackoff: (retryCount, error) => { |
123 | | - log.error('aws sdk request error', { error, retryCount }); |
124 | | - // retry with exponential backoff delay capped at 1mn max |
125 | | - // between retries, and a little added jitter |
126 | | - return Math.min(AWS_SDK_REQUEST_INITIAL_DELAY_MS |
127 | | - * 2 ** retryCount, 60000) |
128 | | - * (0.9 + Math.random() * 0.2); |
129 | | - }, |
130 | | -}; |
131 | | -const s3 = new AWS.S3(Object.assign(options, s3Options)); |
| 109 | + forcePathStyle: true, |
| 110 | + tls: s3EndpointIsHttps, |
| 111 | + requestHandler: new NodeHttpHandler({ |
| 112 | + httpAgent: agent, |
| 113 | + httpsAgent: agent, |
| 114 | + requestTimeout: 0, |
| 115 | + }), |
| 116 | + retryStrategy: new ConfiguredRetryStrategy( |
| 117 | + AWS_SDK_REQUEST_RETRIES, |
| 118 | + // eslint-disable-next-line arrow-body-style |
| 119 | + attempt => { |
| 120 | + // Custom backoff with exponential delay capped at 1mn max |
| 121 | + // between retries, and a little added jitter |
| 122 | + return Math.min(AWS_SDK_REQUEST_INITIAL_DELAY_MS |
| 123 | + * 2 ** attempt, 60000) |
| 124 | + * (0.9 + Math.random() * 0.2); |
| 125 | + } |
| 126 | + ), |
| 127 | +}); |
132 | 128 |
|
133 | 129 | const stats = { |
134 | 130 | current: { |
|
0 commit comments