Skip to content

Commit eb2b632

Browse files
committed
Fix issue with Lambda where streaming repsonses always require a body to be present
1 parent 9b98ce1 commit eb2b632

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/api/lambda.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import awsLambdaFastify from "@fastify/aws-lambda";
22
import { pipeline } from "node:stream/promises";
33
import init, { instanceId } from "./index.js";
44
import { InternalServerError, ValidationError } from "common/errors/index.js";
5+
import { Readable } from "node:stream";
56

67
// Initialize the proxy with the payloadAsStream option
78
const app = await init();
@@ -85,7 +86,12 @@ export const handler = awslambda.streamifyResponse(
8586
responseStream,
8687
meta as any,
8788
);
88-
await pipeline(stream, responseStream);
89+
90+
// Fix issue with Lambda where streaming repsonses always require a body to be present
91+
const body =
92+
stream.readableLength > 0 ? stream : Readable.from(Buffer.from(""));
93+
94+
await pipeline(body, responseStream);
8995
} catch (e) {
9096
console.error("Error during proxy or stream pipeline:", e);
9197
const error = new InternalServerError({

0 commit comments

Comments
 (0)