From af95722ab4d85e695cfe5d683e47bd1671461316 Mon Sep 17 00:00:00 2001 From: Riarstudio <248381781+Riarstudio@users.noreply.github.com> Date: Mon, 12 Oct 2026 09:43:07 -0400 Subject: [PATCH] Migrate lib/upload-s3.js from AWS SDK v2 to v3 (lib-storage Upload) AWS SDK for JavaScript v2 reached end-of-support on September 8, 2025 and receives no security patches (GHSA-j965-2qgj-vjmq). Replace the v2 managed upload s3.upload(...).promise() with the Upload class from @aws-sdk/lib-storage (same partSize/queueSize options) driven by an S3Client from @aws-sdk/client-s3; the logger config moves into the client constructor. package.json: add @aws-sdk/client-s3 and @aws-sdk/lib-storage; aws-sdk stays for lib/iam.js and lib/secrets-manager.js, which are out of scope. --- lib/upload-s3.js | 29 ++++++++++++++--------------- package.json | 2 ++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/upload-s3.js b/lib/upload-s3.js index 1c42338..6bf1d98 100644 --- a/lib/upload-s3.js +++ b/lib/upload-s3.js @@ -1,26 +1,25 @@ -const AWS = require('aws-sdk') - -// configure AWS to log to stdout -AWS.config.update({ - logger: process.stdout -}) +const { S3Client } = require('@aws-sdk/client-s3') +const { Upload } = require('@aws-sdk/lib-storage') async function uploadS3(stream, config, key) { - const s3 = new AWS.S3({ - region: config.S3_REGION + // Construct S3 client with logger + const s3 = new S3Client({ + region: config.S3_REGION, + logger: process.stdout }) - const result = await s3.upload( - { + // Use lib-storage Upload for multipart upload + const upload = new Upload({ + client: s3, + params: { Key: key, Bucket: config.S3_BUCKET, Body: stream, StorageClass: config.S3_STORAGE_CLASS }, - { - partSize: config.S3_PART_SIZE, - queueSize: 1 - } - ).promise() + partSize: config.S3_PART_SIZE, + queueSize: 1 + }) + const result = await upload.done() console.log('Uploaded to', result.Location) return result.Location diff --git a/package.json b/package.json index cfc64a7..8179030 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "description": "Lambda function for executing pg_dump and streaming the output to s3.", "main": "index.js", "dependencies": { + "@aws-sdk/client-s3": "^3.600.0", + "@aws-sdk/lib-storage": "^3.600.0", "aws-sdk": "2.1693.0", "moment": "2.30.1" },