1- const AWS = require ( 'aws-sdk' ) ;
1+ const { S3Client } = require ( '@aws-sdk/client-s3' ) ;
2+ const { NodeHttpHandler } = require ( '@aws-sdk/node-http-handler' ) ;
3+ const { ConfiguredRetryStrategy } = require ( '@smithy/util-retry' ) ;
24const http = require ( 'http' ) ;
5+ const https = require ( 'https' ) ;
36const BackbeatClient = require ( '../BackbeatClient' ) ;
47
58const AWS_SDK_REQUEST_DELAY_MS = 30 ;
69const AWS_SDK_REQUEST_RETRIES = 100 ;
7- const LOG_PROGRESS_INTERVAL_MS = 10000 ;
810
911/**
1012 * Sets up and configures AWS S3 and Backbeat clients.
@@ -27,7 +29,34 @@ function setupClients({
2729 secretKey,
2830 endpoint,
2931} , log ) {
30- const awsConfig = {
32+ const awsv3Config = {
33+ region : 'us-east-1' ,
34+ credentials : {
35+ accessKeyId : accessKey ,
36+ secretAccessKey : secretKey ,
37+ } ,
38+ endpoint,
39+ forcePathStyle : true ,
40+ requestHandler : new NodeHttpHandler ( {
41+ httpAgent : new http . Agent ( { keepAlive : true } ) ,
42+ httpsAgent : new https . Agent ( {
43+ keepAlive : true ,
44+ rejectUnauthorized : false // Equivalent to sslEnabled: false
45+ } ) ,
46+ requestTimeout : 0 ,
47+ } ) ,
48+ retryStrategy : new ConfiguredRetryStrategy (
49+ AWS_SDK_REQUEST_RETRIES , // maxAttempts
50+ attempt => {
51+ log . error ( 'aws sdk request error' , { retryCount : attempt } ) ;
52+ // The delay is not truly exponential; it resets to the minimum after every 10 calls,
53+ // with a maximum delay of 15 seconds.
54+ return AWS_SDK_REQUEST_DELAY_MS * ( 2 ** ( attempt % 10 ) ) ;
55+ }
56+ )
57+ } ;
58+
59+ const awsv2Config = {
3160 accessKeyId : accessKey ,
3261 secretAccessKey : secretKey ,
3362 endpoint,
@@ -43,32 +72,10 @@ function setupClients({
4372 } ,
4473 } ;
4574
46- /**
47- * Custom backoff strategy for AWS SDK requests.
48- * @param {number } retryCount - The current retry attempt.
49- * @param {Error } error - The error that caused the retry.
50- * @returns {number } The delay in milliseconds before the next retry.
51- */
52- function customBackoffStrategy ( retryCount , error ) {
53- this . log . error ( 'aws sdk request error' , { error, retryCount } ) ;
54- // The delay is not truly exponential; it resets to the minimum after every 10 calls,
55- // with a maximum delay of 15 seconds.
56- return AWS_SDK_REQUEST_DELAY_MS * ( 2 ** ( retryCount % 10 ) ) ;
57- }
58-
59- // Specific options for S3 requests
60- const s3SpecificOptions = {
61- maxRetries : AWS_SDK_REQUEST_RETRIES ,
62- customBackoff : customBackoffStrategy ,
75+ return {
76+ s3 : new S3Client ( awsv3Config ) ,
77+ bb : new BackbeatClient ( awsv2Config ) ,
6378 } ;
64-
65- // Create an S3 client instance
66- const s3 = new AWS . S3 ( { ...awsConfig , ...s3SpecificOptions } ) ;
67-
68- // Create a BackbeatClient instance
69- const bb = new BackbeatClient ( awsConfig ) ;
70-
71- return { s3, bb } ;
7279}
7380
7481module . exports = { setupClients } ;
0 commit comments