What is @aws-sdk/middleware-endpoint?
The @aws-sdk/middleware-endpoint package is part of the AWS SDK for JavaScript v3. It is used to manage and resolve endpoints in AWS service calls. This middleware allows developers to customize endpoint resolution logic, which can be useful for directing requests to specific regions, using custom domain names, or working with mock endpoints for testing purposes.
What are @aws-sdk/middleware-endpoint's main functionalities?
Custom Endpoint Resolution
This code demonstrates how to use the @aws-sdk/middleware-endpoint package to customize the endpoint for an S3 client. It adds a middleware that resolves to a custom endpoint, which is useful for directing requests to a specific server or for testing with mock endpoints.
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
const { endpointMiddleware } = require('@aws-sdk/middleware-endpoint');
const client = new S3Client({
region: 'us-west-2'
});
client.middlewareStack.add(endpointMiddleware({
endpoint: () => ({
protocol: 'https:',
hostname: 'my-custom-s3-endpoint.com',
path: '/',
query: {}
})
}), {
step: 'build'
});
const command = new GetObjectCommand({ Bucket: 'example-bucket', Key: 'example-object' });
client.send(command);
Other packages similar to @aws-sdk/middleware-endpoint
@aws-sdk/middleware-retry
This package provides middleware for handling retries of requests in AWS SDK for JavaScript v3. It is similar to @aws-sdk/middleware-endpoint in that it modifies the request handling pipeline, but it focuses on retry logic rather than endpoint resolution.
@aws-sdk/middleware-logger
The @aws-sdk/middleware-logger package allows logging of requests and responses in the AWS SDK for JavaScript v3. Like @aws-sdk/middleware-endpoint, it enhances the SDK's capabilities by adding middleware that intercepts and logs all service interactions, although its primary focus is on logging rather than endpoint management.