Skip to content

Commit 0f8898c

Browse files
authored
docs(UPGRADING): describe S3 getObject buffer vs. stream (#5782)
* docs(UPGRADING): describe S3 getObject buffer vs. stream * docs(UPGRADING): add comment
1 parent 0cb2dd7 commit 0f8898c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

UPGRADING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,29 @@ In v3, the similar utility function is available in [`@aws-sdk/polly-request-pre
571571

572572
## Notes on Specific Service Clients
573573

574+
### Amazon S3
575+
576+
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
577+
returns a `Stream` in JSv3.
578+
579+
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.
580+
581+
```ts
582+
// v2
583+
const get = await s3.getObject({ ... }).promise(); // this buffers (consumes) the stream already.
584+
```
585+
586+
```ts
587+
// v3, consume the stream to free the socket.
588+
const get = await s3.getObject({ ... }); // object .Body has unconsumed stream.
589+
const str = await get.Body.transformToString(); // consumes the stream.
590+
// other ways to consume the stream include writing it to a file,
591+
// passing it to another consumer like an upload, or buffering to
592+
// a string or byte array.
593+
```
594+
595+
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
596+
574597
### AWS Lambda
575598

576599
Lambda invocations response type differs in v3:

0 commit comments

Comments
 (0)