What is @aws-sdk/middleware-user-agent?
The @aws-sdk/middleware-user-agent package is part of the AWS SDK for JavaScript (v3). It is used to manage and customize the User-Agent header sent in requests made to AWS services. This middleware allows developers to append additional information to the User-Agent header, which can be useful for debugging, tracking, and analytics purposes.
Customizing User-Agent
This code demonstrates how to customize the User-Agent header when creating an S3 client instance. It appends 'MyApp/1.0.0' to the default User-Agent string provided by AWS SDK.
const { S3Client } = require('@aws-sdk/client-s3');
const { defaultUserAgent } = require('@aws-sdk/util-user-agent-node');
const { addUserAgent } = require('@aws-sdk/middleware-user-agent');
const client = new S3Client({
region: 'us-west-2',
customUserAgent: 'MyApp/1.0.0'
});
addUserAgent(client, defaultUserAgent({ serviceId: 'S3', clientVersion: '3.0.0' }));