Support bun (an all-in-one JavaScript runtime)
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:
-
Added a bun layer containing a bootstrap script and a binary (based on arm arch). see official docs
-
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", }, });
},
}
- Wrote an index file with the expected format by AWS:
index.ts
import lambda from "./lambda";
export default {
js: lambda.fetch
};
- Build the lambda using bun for the
buntarget:
bun build --target=bun --minify --outfile=index.js index.ts
- Deploy
index.jswith matching runtime and arch.
We've definitely looked at this. Thoughts @thdxr?
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).
Do you think we need to switch the esbuild part of it though?
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.
https://github.com/oven-sh/bun/issues/5549
Any updates on supporting bun in general?
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