Write a file to S3 in Node.js
Once I had figured out how to read a file from S3, I then had to write one. Given that the text I had to write wasn’t large, this turned out to be very straightforward. Tested with AWS SDK v3.45.
const AWS = require("@aws-sdk/client-s3");
const writeFile = async (bucket, filename, text) => {
const s3 = new AWS.S3();
await s3.putObject({
Bucket: bucket,
Key: filename,
Body: Buffer.from(text)
})
}