What is @aws-sdk/middleware-apply-body-checksum?
@aws-sdk/middleware-apply-body-checksum is a middleware package for the AWS SDK for JavaScript. It is used to automatically apply checksums to the body of requests, ensuring data integrity during transmission.
Apply Checksum to Request Body
This feature demonstrates how to apply a checksum to the body of a request using the @aws-sdk/middleware-apply-body-checksum package. The middleware is added to the S3 client's middleware stack, ensuring that the body of the PutObjectCommand request is checksummed before being sent.
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const { applyBodyChecksumMiddleware } = require('@aws-sdk/middleware-apply-body-checksum');
const client = new S3Client({ region: 'us-west-2' });
client.middlewareStack.add(applyBodyChecksumMiddleware(), {
step: 'build',
priority: 'high',
});
const command = new PutObjectCommand({
Bucket: 'example-bucket',
Key: 'example-object',
Body: 'Hello, world!',
});
client.send(command).then((response) => {
console.log('Success', response);
}).catch((error) => {
console.error('Error', error);
});