What is @aws-sdk/middleware-signing?
The @aws-sdk/middleware-signing package is part of the AWS SDK for JavaScript (v3). It provides middleware for signing requests made to AWS services. This is crucial for authenticating requests by automatically including secure signatures in API calls. The package ensures that AWS service requests are transmitted securely and are authenticated using the appropriate AWS credentials.
Request Signing
This code demonstrates how to add the AWS authentication middleware to an S3 client instance in the AWS SDK. It ensures that the PutObjectCommand is signed correctly before being sent to AWS.
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { awsAuthMiddleware } from '@aws-sdk/middleware-signing';
const client = new S3Client({});
client.middlewareStack.add(awsAuthMiddleware(), {
step: 'finalizeRequest',
name: 'awsAuthMiddleware',
tags: { SET_CONTEXT: true },
override: true
});
const command = new PutObjectCommand({ Bucket: 'example-bucket', Key: 'example-object', Body: 'Hello, world!' });
client.send(command);