When migrating to the AWS SDK for JavaScript v3, I first replaced the old client with an S3 client configured for the region where my bucket resides. This step lays the foundation: the same client can then be used for various operations.
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const client = new S3Client({ region: "us-east-1" });
Next, I adapted the file upload process. With the old syntax, I would call upload on the bucket object and append .promise(). With the new syntax, I construct a PutObjectCommand and then send it using client.send():
// Old code
await bucket.upload(params).promise();
// New code
await client.send(new PutObjectCommand(params));
The parameters remain familiar. To upload file.txt to my-bucket, I define them once and then pass them to the command:
const params = {
Bucket: "my-bucket",
Key: "file.txt",
Body: "File content",
};
The underlying upload logic doesn't really change; it’s primarily the way the operation is formulated that evolves. In my own code, this migration helped me better perceive each action as a distinct command.