0

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 */
James
  • 411
  • 4
  • 20
  • 1
    May be helpful: [stream to string](https://stackoverflow.com/questions/10623798/how-do-i-read-the-contents-of-a-node-js-stream-into-a-string-variable) and [string to stream](https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js). – jarmod Sep 20 '22 at 19:09

0 Answers0