sst icon indicating copy to clipboard operation
sst copied to clipboard

Support bun (an all-in-one JavaScript runtime)

Open dror-weiss opened this issue 2 years ago • 6 comments

Bun is growing and its official 1.0 launch is near (09-2023).

I would love to see sst supporting bun as an AWS provided runtime.

The gist of my bun lambda setup:

  1. Added a bun layer containing a bootstrap script and a binary (based on arm arch). see official docs

  2. Wrote a lambda: lambda.ts

export default { 
  async fetch(request: Request): Promise<Response> { 
    console.log(request.headers.get("x-amzn-function-arn")); 
    // ... 
    return new Response("Hello from Lambda!", { status: 200, headers: { "Content-Type": "text/plain", }, }); 
  }, 
}
  1. Wrote an index file with the expected format by AWS: index.ts
import lambda from "./lambda";

export default {
  js: lambda.fetch
};
  1. Build the lambda using bun for the bun target:
bun build --target=bun --minify --outfile=index.js index.ts
  1. Deploy index.js with matching runtime and arch.

dror-weiss avatar Aug 28 '23 09:08 dror-weiss

We've definitely looked at this. Thoughts @thdxr?

jayair avatar Aug 31 '23 22:08 jayair

I've started working on a PR for this but it will take me some time to understand the code enough to complete it.

Right now I have encountered a few difficulties in implementing the build/cache process, despite Bun.build being heavily inspired by esbuild (what's used in node).

dror-weiss avatar Sep 01 '23 10:09 dror-weiss

Do you think we need to switch the esbuild part of it though?

jayair avatar Sep 03 '23 22:09 jayair

I think the bun handler that needs to be added in packages/sst/src/runtime/handlers should use Bun.build.

I also think that someone with an intimate understanding of the codebase would be a better fit than me, as it's taking me more time than expected to issue a PR with this support. If there are guidelines for the codebase itself (more detailed than the one for contributors) I can try it.

dror-weiss avatar Sep 04 '23 08:09 dror-weiss

https://github.com/oven-sh/bun/issues/5549

5o50 avatar Sep 16 '23 12:09 5o50

Any updates on supporting bun in general?

ivawzh avatar Sep 21 '24 16:09 ivawzh

We are transition this repo to https://github.com/sst/v2 and are closing this issue for now. If it is still relevant please reopen it there - sorry for the trouble

thdxr avatar Oct 21 '24 18:10 thdxr