I'm trying to append a block of text to a markdown file stored in S3.
I know that S3 doesn't allow you to "append". I need to read the file's contents, append to them, and re-upload a file with the same name to replace it.
I'm not familiar with NodeJS streams—what's the most efficient approach to read the stream returned by getObject()
, append to it, and reupload with putObject()
?
/* Get the file from the bucket */
const data = await client.send(
new GetObjectCommand({
Bucket: context.AWS_BUCKET_NAME,
Key: key,
})
);
/* Pipe the response body into a writeable stream */
/* Then append the message to the file */
/* Finally, upload the file to the bucket */