oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.5k stars 2.79k forks source link

Bun - S3 SignatureDoesNotMatch when using fs.createReadStream #12292

Open lifeeric opened 5 months ago

lifeeric commented 5 months ago

What version of Bun is running?

1.1.17

What platform is your computer?

mac

What steps can reproduce the bug?

This simple nodejs code throws the below error:

import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import fs from "node:fs";
import mime from "mime-types";

const s3Client = new S3Client({
  region: "us-east-1",
  credentials: {
    accessKeyId: "x",
    secretAccessKey: "x",
  },
});

const command = new PutObjectCommand({
  Bucket: "test",
  Key: `__outputs/index.html`,
  Body:  fs.createReadStream("./output/dist/index.html"),
  ContentType: mime.lookup("./output/dist/index.html"),
});

(async () => {
  await s3Client.send(command);
})();

What is the expected behavior?

It should upload the file successfully, but instead it throws error:

SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.

It took me an entire day to figure out the issue, and it only happening when using bun instead of Node.

What do you see instead?

No response

Additional information

No response

kaloyanBozhkov commented 4 months ago

Having the same issue

kaloyanBozhkov commented 4 months ago

Seems like this approach works for now https://github.com/oven-sh/bun/issues/6803#issuecomment-2199635069