CodeGenieApp / CodeGenieApp/serverless-express
Feat: Add AWS Lambda Response Streaming support
- Vorherrschende Sprache
- JavaScript
- Sterne
- 5.3k
- Forks
- 676
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
## 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);
}
);
Beitragsleitfaden
Rechercherichtung
Beginne am öffentlichen serverlessExpress-Aufruf-Einstiegspunkt und verfolge den bestehenden Pfad zur Antwortpufferung. Überprüfe die im Issue beschriebenen Formen der async- und callback-Argumente und stelle anschließend sicher, dass die Unterstützung für responseStream bestehende Aufrufe beibehält und gleichzeitig gestreamte Antworten über AWS Lambda ermöglicht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- aws, express, javascript, node.js
- Bereich
- api, backend, cloud
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100