What is @aws-sdk/middleware-bucket-endpoint?
The @aws-sdk/middleware-bucket-endpoint package is part of the AWS SDK for JavaScript (v3). It provides middleware that automatically configures the endpoint for S3 bucket operations, allowing users to interact with different S3 bucket configurations and regions more seamlessly. This package is particularly useful for managing requests to S3 buckets by modifying the endpoint based on the operation and the provided bucket parameters.
Automatic Endpoint Resolution
This code sample demonstrates how to integrate the bucketEndpointMiddleware into an S3 client instance. It automatically resolves the correct endpoint for the bucket specified in the command.
import { S3Client, GetObjectCommand } from '@aws-sdk/client-s3';
import { bucketEndpointMiddleware } from '@aws-sdk/middleware-bucket-endpoint';
const client = new S3Client({
region: 'us-west-2',
middlewareStack: {
add: (middleware) => middleware(bucketEndpointMiddleware())
}
});
const command = new GetObjectCommand({ Bucket: 'example-bucket', Key: 'example-object' });
client.send(command);