I'm trying to fetch the contents of a file in an s3 bucket, so I can parse it as JSON and do stuff with it. I'm using the aws js sdk version 3, with typescript. The code snippet at https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/s3/actions/get-object.js#L22 doesn't work: NodeJS complains that transformToString
isn't a function on the item:
const response = await client.send(
new GetObjectCommand({ Bucket: "the-bucket-name", Key: "the-file.json" })
);
const str = await (response.Body as any).transformToString();
TypeError: response.Body.transformToString is not a function
I believe the bucket and key are correct; if I change them, I get a different error:
AccessDenied: Access Denied
How can I get the contents of the item into a string so I can parse it as JSON? I'm using the following package versions:
"@aws-sdk/client-s3": "^3.35.0",
"@aws-sdk/client-secrets-manager": "^3.35.0",
"@aws-sdk/client-sts": "^3.35.0",
"@aws-sdk/credential-provider-node": "^3.35.0",
"@aws-sdk/s3-request-presigner": "^3.35.0",