lightning web components – Migrating from AWS JS SDK V2 to V3

Has anyone moved from AWS JS SDK V2 to V3? I’m trying to do it. Used webpack to bundle client-s3 and s3-request-presigner. Uploaded that as a static resource. Used the following to load it

import { loadScript } from "lightning/platformResourceLoader";

This is the webpack config file

const path = require("path");

module.exports = {
  entry: "./aws-sdk.js", // Entry point for the AWS SDK modules
  output: {
    path: path.resolve(__dirname, ""), // Output directory
    filename: "AWSJSSDKV3.js", // Output file name
    library: "AWS",
    libraryTarget: "window" // Attach to the window object
  },
  mode: "development",
  optimization: {
    minimize: true // Minify the output for production
  }
};

This is the entry point:

import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
// Expose the required AWS SDK v3 modules globally
window.AWS = {
  S3Client,
  getSignedUrl,
  PutObjectCommand,
  GetObjectCommand
};

When I’m trying to access it in my LWC, window.AWS is returning an empty object. Ideally, I should be able to access s3Client from window.AWS

const { s3Client } = window.AWS;

Read more here: Source link