Amazon Web Services · sdk · fg-0180
S3 GetObject Body.toString() returns [object Object] or a stream instead of the file contents in AWS SDK v3
response.Body.toString() prints [object Object] or IncomingMessage
Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100
Cause
In SDK v3 the Body is a runtime stream, not a Buffer as in v2. Later v3 releases attach helper methods to the stream that read it for you.
Fix
Await Body.transformToString() or transformToByteArray(). Read it once, because the stream is consumed by the first read.
Apply
const res = await s3.send(new GetObjectCommand({ Bucket, Key }));
const text = await res.Body.transformToString();
const data = JSON.parse(text);Affects: AWS SDK for JavaScript v3, @aws-sdk/client-s3 all versions; transformToString exists in releases from late 2022 onward
Sources
- https://github.com/aws/aws-sdk-js-v3/issues/1877
- https://github.com/aws/aws-sdk-js-v3/blob/main/README.md
Have your agent know this before it fails
claude mcp add --transport http footgun https://getfootgun.com/api/mcp