1import { S3Client } from '@aws-sdk/client-s3' 2import { NodeHttpHandler } from '@smithy/node-http-handler' 6export const getS3Client = ({bucket_name, socketTimeoutMs, keepAlive}: {bucket_name: string, socketTimeoutMs?: number, keepAlive?: boolean}) => { 7 const cfg = getS3ReqCfg({bucket_name}) as Record<string, string> 9 let {region, endpoint, s3ForcePathStyle, accessKeyId, secretAccessKey} = cfg 10 region ||= defaultS3Region 12 const handlerOpts: Record<string, any> = {} 13 if (socketTimeoutMs !== undefined) handlerOpts.socketTimeout = socketTimeoutMs 14 if (keepAlive !== undefined) handlerOpts.httpsAgent = {keepAlive} 16 const s3 = new S3Client({ 17 requestChecksumCalculation: 'WHEN_REQUIRED', 18 forcePathStyle: !!s3ForcePathStyle, 21 accessKeyId, secretAccessKey, 23 ...(Object.keys(handlerOpts).length ? {requestHandler: new NodeHttpHandler(handlerOpts)} : {}),