Skip to content

Commit

Permalink
docs(UPGRADING): describe S3 getObject buffer vs. stream (#5782)
Browse files Browse the repository at this point in the history
* docs(UPGRADING): describe S3 getObject buffer vs. stream

* docs(UPGRADING): add comment
  • Loading branch information
kuhe committed Feb 13, 2024
1 parent 0cb2dd7 commit 0f8898c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,29 @@ In v3, the similar utility function is available in [`@aws-sdk/polly-request-pre

## Notes on Specific Service Clients

### Amazon S3

Streaming vs. buffered responses: the JSv3 SDK prefers not to buffer potentially large responses. This is commonly encountered in S3's GetObject operation, which returned a `Buffer` in JSv2, but
returns a `Stream` in JSv3.

For Node.js, you must consume the stream or garbage collect the client or its request handler to keep the connections open to new traffic by freeing sockets.

```ts
// v2
const get = await s3.getObject({ ... }).promise(); // this buffers (consumes) the stream already.
```

```ts
// v3, consume the stream to free the socket.
const get = await s3.getObject({ ... }); // object .Body has unconsumed stream.
const str = await get.Body.transformToString(); // consumes the stream.
// other ways to consume the stream include writing it to a file,
// passing it to another consumer like an upload, or buffering to
// a string or byte array.
```

Please see also the section on **socket exhaustion** here: https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#request-handler-requesthandler

### AWS Lambda

Lambda invocations response type differs in v3:
Expand Down

0 comments on commit 0f8898c

Please sign in to comment.