New preset: aws-lambda streaming with REST API v1 support #4036
justcloudnative
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
|
Thanks for headsup. We are moving AWS support to srvx lambda do you mind to raise an issue in srvx + links to any announcement from AWS? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Idea
Add a new preset for AWS Lambda streaming that supports the REST API v1 (API Gateway) event format.
Context
The existing
aws-lambdapreset withstreaming: trueonly supports the HTTP API v2 event format. AWS recentlyadded response streaming support to REST API v1 via
responseTransferMode: "STREAM"in the OpenAPI integrationconfiguration, opening up Lambda streaming to REST API v1 users.
REST API v1 is still widely used because of features not available in HTTP API v2:
What the new preset would do
Handle the REST API v1 event format in a streaming Lambda handler:
event.path(v1) instead ofevent.rawPath(v2) for routingevent.httpMethod(v1) instead ofevent.requestContext.http.method(v2)event.multiValueQueryStringParameters(v1 only) in the query objectawslambda.streamifyResponseProposed changes
The change is in
src/presets/aws-lambda/runtime/aws-lambda-streaming.ts:import type { Readable } from "node:stream"; -import type { APIGatewayProxyEventV2 } from "aws-lambda"; +import type { + APIGatewayProxyEvent, + APIGatewayProxyEventV2, +} from "aws-lambda"; import "#nitro-internal-pollyfills"; import { useNitroApp } from "nitropack/runtime"; import { @@ -15,12 +17,19 @@ const nitroApp = useNitroApp(); export const handler = awslambda.streamifyResponse( - async (event: APIGatewayProxyEventV2, responseStream, context) => { + async ( + event: APIGatewayProxyEvent | APIGatewayProxyEventV2, + responseStream, + context, + ) => { const query = { ...event.queryStringParameters, + ...(event as APIGatewayProxyEvent).multiValueQueryStringParameters, }; - const url = withQuery(event.rawPath, query); - const method = event.requestContext?.http?.method || "get"; + const url = withQuery( + (event as APIGatewayProxyEvent).path || + (event as APIGatewayProxyEventV2).rawPath, + query, + ); + const method = + (event as APIGatewayProxyEvent).httpMethod || + (event as APIGatewayProxyEventV2).requestContext?.http?.method || + "get";This aligns the streaming handler with the non-streaming handler (
aws-lambda.ts) which already supports both v1 andv2. The response handling (
isApiGwV2check, cookies,multiValueHeaders) already works for both formats — onlythe request parsing needs updating.
Beta Was this translation helpful? Give feedback.
All reactions