CodeGenieApp / CodeGenieApp/serverless-express

Feat: Add AWS Lambda Response Streaming support

Aperta
#715 0 commenti 4 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
5.3k
Fork
676
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Problem / Motivation
Currently, `@codegenie/serverless-express` buffers the entire Express response in memory before transforming it into the standard Lambda proxy response object. This architecture introduces two main limitations:
1. **6 MB Payload Limit:** We are bound by the strict 6 MB limit for synchronous Lambda responses.
2. **TTFB (Time to First Byte):** For large payloads (like large JSON datasets, file downloads, or SSR pages), the client has to wait until the entire Express response is fully buffered before receiving any data.

AWS supports **Lambda Response Streaming**, which allows functions to stream payloads back to the client, bypassing the 6 MB limit (up to 20 MB) and drastically improving TTFB.

Ref: https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/

## Proposed Solution
We can introduce support for response streaming by extending the `serverlessExpress` instance signature.

Since the existing implementation can accept a `callback` function, we should introduce a backward-compatible overloading (type checking) to accept the `responseStream` object either as the **third argument** (when `callback` is omitted in async handlers) or as the **fourth argument** (if a callback is present).

Under the hood, the package will detect the presence of the `responseStream` object and stream/pipe the Express `res` object directly into it instead of buffering the response.

## Proposed Usage Idea

Here is how the implementation will look from the user's perspective using the standard `async/await` pattern (which is the default for Lambda response streaming):

```typescript
import serverlessExpress from '@codegenie/serverless-express';
import app from './app';

const serverlessExpressInstance = serverlessExpress({ app });

export const handler = awslambda.streamifyHandler(
async (event, responseStream, context) => {
// Overloading: passing responseStream as the 3rd argument
return serverlessExpressInstance(event, context, responseStream);
}
);

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dal punto di ingresso pubblico per l’invocazione di serverlessExpress e segui il percorso esistente di buffering delle risposte. Controlla le forme degli argomenti async e callback descritte nell’issue, quindi verifica che il supporto per responseStream mantenga le chiamate esistenti consentendo al contempo risposte trasmesse tramite AWS Lambda.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, express, javascript, node.js
Ambito
api, backend, cloud
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.