Skip to content

[Discussion] RedwoodJS uses the AWS Lambda Handler syntax on Vercel, preventing use of new features #12073

@QuiiBz

Description

@QuiiBz

What's not working?

👋 I work at Vercel on our compute products. I'm opening this issue to discuss about the best way forward to support RedwoodJS with our latest features.

We recently came across an issue for our customers using RedwoodJS: most of our new features like HTTP response streaming, waitUntil, and Fluid compute do not work with RedwoodJS, as the serverless functions follow the AWS Lambda Handler signature: https://docs.redwoodjs.com/docs/serverless-functions

For reference, this signature looks like this:

export const handler = async (event, context) => {
  return {
    statusCode: ...,
    headers: ...,
    body: ...,
  }
}

Inside the RedwoodJS builder in the Vercel CLI, we support this signature via the awsLambdaHandler property: https://github.com/vercel/vercel/blob/f706e63184d352d5fdd68b702aac8d32b321b0fe/packages/redwood/src/index.ts#L303

This awsLambdaHandler property is documented here and kept for backward-compatibility, but opts out functions from the features mentioned above due to this API: for example, you cannot stream back an HTTP response by just returning a body string.

On Vercel, Netlify, Cloudflare Workers, and other providers, we instead use the web-standard Request / Response objects. There are slight differences regarding how the handler gets exported, but the actual function always follows this signature:

const handler = async (request: Request, ...args?: unknown) => {
  return new Response(...)
}

Is there any plan to change the output format (and not necessarily the framework's API, as this would be a breaking change for users of RedwoodJS) to use the web handlers signature? This change could happen on either the RedwoodJS side when running rw deploy vercel, or on Vercel's RedwoodJS builder. Here's a pseudo-code of what this would look like:

// User code
const handler = async (event, context) => { ... }

const vercelHandler = async (request: Request) => {
  const { event, context } = await webRequestToAWS(request)
  const response = await handler(event, context)
  return awsToWebResponse(response) 
}

export const GET = vercelHandler
export const POST = vercelHandler

I'm not very familiar with Redwood, but I'd assume that this would also be worth it for RedwoodJS users using Netlify or other providers that use the same AWS Lambda Handler syntax, but could benefit from HTTP streaming, waitUntil, etc.

Let me know your thoughts on what would be the best way to implement this change, and happy to answer any other questions you may have.

How do we reproduce the bug?

What's your environment? (If it applies)

-

Are you interested in working on this?

  • I'm interested in working on this

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/needs-infoMore information is needed for reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions