Skip to content

Commit 9b98ce1

Browse files
committed
fix response streaming
1 parent 438a8ba commit 9b98ce1

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/api/lambda.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { InternalServerError, ValidationError } from "common/errors/index.js";
77
const app = await init();
88
const proxy = awsLambdaFastify(app, {
99
payloadAsStream: true,
10-
decorateRequest: false, // from original code
11-
serializeLambdaArguments: true, // from original code
10+
decorateRequest: false,
11+
callbackWaitsForEmptyEventLoop: false,
12+
serializeLambdaArguments: true,
1213
binaryMimeTypes: ["application/octet-stream", "application/vnd.apple.pkpass"], // from original code
1314
});
1415

@@ -79,20 +80,12 @@ export const handler = awslambda.streamifyResponse(
7980

8081
// 3. If validation passes, proxy the request and stream the response
8182
try {
82-
// The proxy returns a body stream and metadata
83-
const { stream: fastifyResponseStream, ...meta } = await proxy(
84-
event,
85-
context,
86-
);
87-
88-
// Use the helper to apply the status code/headers from Fastify
89-
const httpResponseStream = awslambda.HttpResponseStream.from(
83+
const { stream, meta } = await proxy(event, context);
84+
responseStream = awslambda.HttpResponseStream.from(
9085
responseStream,
91-
meta,
86+
meta as any,
9287
);
93-
94-
// Pipe the response from Fastify to the Lambda output stream
95-
await pipeline(fastifyResponseStream, httpResponseStream);
88+
await pipeline(stream, responseStream);
9689
} catch (e) {
9790
console.error("Error during proxy or stream pipeline:", e);
9891
const error = new InternalServerError({

0 commit comments

Comments
 (0)