aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.1k stars 578 forks source link

Changes to `@aws-sdk/signature-v4-multi-region` used by S3 MRAP and EventBridge #5229

Open kuhe opened 1 year ago

kuhe commented 1 year ago

Announcement

In an upcoming release for the AWS SDK for JavaScript v3, version TBD, the usage of the @aws-sdk/signature-v4-crt package will change.

*** this has been merged will be released on Oct 26, 2023.

See PR: https://github.com/aws/aws-sdk-js-v3/pull/5225

Who is affected?

Users of @aws-sdk/signature-v4-crt. This is an optional package used by the S3 MRAP feature and EventBridge clients. https://www.npmjs.com/package/@aws-sdk/signature-v4-crt

What is changing and why?

Currently, this package is imported dynamically by SDK code calling the Node.js require global function. Because this is disruptive to bundlers both in the browser and server-side, and because it is difficult to analyze statically, the dynamic import is being removed.

Users will need to make an explicit call or import statement to register the functionality of the optional package. Instructions from the PR are duplicated here:

Code example (ESM):

import "@aws-sdk/signature-v4-crt"; // this import is now required to access multi-region signing

import { S3 } from "@aws-sdk/client-s3";

const client = new S3({});

const command = {
  Bucket: "arn:aws:s3::<ID>:accesspoint/<MY_MRAP_ID>.mrap",
  Key: "Example Key",
  Body: "Example Body",
};

await client.putObject(command);

Code example (CJS):

require("@aws-sdk/signature-v4-crt"); // this import is now required to access multi-region signing

const { S3 } = require("@aws-sdk/client-s3");

const client = new S3({});

const command = {
  Bucket: "arn:aws:s3::<ID>:accesspoint/<MY_MRAP_ID>.mrap",
  Key: "Example Key",
  Body: "Example Body",
};

await client.putObject(command);

You can make this change to your code in any SDK version, ahead of time, to prepare for the change.

After it is released, an error will be thrown if the import is missing. It will say:

Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly.
You must also register the package by calling [require("@aws-sdk/signature-v4-crt");]
or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";].
For more information please go to
https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt"

and the docs in our readme will be updated to the same.

kuhe commented 1 year ago

September 25th, 2023: a warning is now emitted when the @aws-sdk/signature-v4-crt package is loaded dynamically by the SDK when executing an operation that requires it. The warning instructs the user to explicitly import the package instead.

This warning will become an error going forward from the date the announced change is finalized.

kuhe commented 1 year ago

We're expecting to finalize this change on or soon after October 25, 2023.

rjmackay commented 1 year ago

Could this be added to the documentation? Ideally at least in the readme for the eventbridge client and the eventbridge docs (https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-global-endpoints.html#eb-ge-sdk-update). It's mentioned very briefly there, but nothing actually explains how you have to import this.

kuhe commented 1 year ago

This change has been merged and will be in the next release.

jhuamanchumo commented 9 months ago

Is it posible to use an MRAP endpoint with amplify-js?

Amplify.configure({
  Storage: {
    S3: {
      bucket: 'arn:aws:s3::<Account-ID>:accesspoint/<MY_MRAP_ID>.mrap)', 
      region: 'us-east-1' 
    }
  }
});

https://docs.amplify.aws/javascript/tools/libraries/configure-categories/#storage-amazon-s3

kuhe commented 9 months ago

aws-crt is currently not available in the browser, so I do not expect MRAP to work in that case.