feat(aws-lambda): add AWS Lambda adapter with response streaming - #48
Conversation
Adds @standardserver/aws-lambda, which converts API Gateway proxy events (payload format 1.0) into StandardLazyRequest and writes StandardResponse through the stream provided by awslambda.streamifyResponse, sending status, headers, and cookies via the awslambda.HttpResponseStream metadata prelude.
…e utils canWriteToNodeResponse and getNodeResponseError previously trusted only the inner http2 stream when one exists; now the response's own state is checked and used as an error fallback too, so wrappers carrying their own writable state are no longer misjudged.
@standardserver/aws-lambda
@standardserver/bun
@standardserver/core
@standardserver/deno
@standardserver/fastify
@standardserver/fetch
@standardserver/node
@standardserver/peer
@standardserver/shared
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
Adds a new AWS Lambda adapter package that maps API Gateway (v1/v2) events into StandardLazyRequest and writes StandardResponse via awslambda.streamifyResponse for true response streaming, plus a small hardening change in the Node adapter response writability/error checks.
Changes:
- Introduces
@standardserver/aws-lambdawith event → request conversion, header/url/body normalization, and streamed response writing. - Adds comprehensive unit + type-level tests for the new adapter package.
- Updates Node adapter utilities to validate both the response wrapper and underlying http2 stream.
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds the new @standardserver/aws-lambda package to the project package list. |
| pnpm-lock.yaml | Adds the new workspace package and pins dev deps (@types/aws-lambda, bumps @types/node, etc.). |
| playgrounds/node-http/package.json | Bumps @types/node devDependency version. |
| playgrounds/hono-node/package.json | Bumps @hono/node-server and @types/node devDependency versions. |
| packages/node/src/utils.ts | Updates response writability/error helpers to account for underlying http2 stream state/errors. |
| packages/node/package.json | Bumps @types/node devDependency version. |
| packages/fastify/package.json | Bumps @types/node devDependency version. |
| packages/aws-lambda/tsconfig.json | Adds TS project config for the new aws-lambda package. |
| packages/aws-lambda/package.json | Defines the new package metadata, exports, deps, and build/typecheck scripts. |
| packages/aws-lambda/README.md | Documents adapter behavior, usage, and Lambda-specific caveats. |
| packages/aws-lambda/src/index.ts | Exposes the adapter’s public API surface. |
| packages/aws-lambda/src/index.test.ts | Basic export-surface sanity test. |
| packages/aws-lambda/src/types.ts | Defines structural event/stream/global types without polluting consumer globals. |
| packages/aws-lambda/src/types.test-d.ts | Compile-time compatibility checks vs @types/aws-lambda. |
| packages/aws-lambda/src/url.ts | Implements v1/v2 URL reconstruction (including v1 query re-encoding). |
| packages/aws-lambda/src/url.test.ts | Tests v1/v2 URL reconstruction behavior. |
| packages/aws-lambda/src/headers.ts | Implements v1/v2 header normalization + set-cookie splitting for Lambda metadata. |
| packages/aws-lambda/src/headers.test.ts | Tests header normalization, cookie restoration, and set-cookie handling. |
| packages/aws-lambda/src/body.ts | Implements buffered body decoding + hint/content-type/content-length-based parsing. |
| packages/aws-lambda/src/body.test.ts | Tests body parsing across supported hints and encodings. |
| packages/aws-lambda/src/request.ts | Builds StandardLazyRequest from events and response-stream abort signal. |
| packages/aws-lambda/src/request.test.ts | Tests lazy headers, method/url/body resolution, and abort behavior. |
| packages/aws-lambda/src/response.ts | Streams StandardResponse via Lambda response-stream metadata prelude + body piping. |
| packages/aws-lambda/src/response.test.ts | Tests buffered and streaming responses, cookies/headers metadata, and error/close handling. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| }) | ||
|
|
||
| // WARNING: errors that occur here are silently ignored and not reported to the Promise |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Adds
@standardserver/aws-lambda, an adapter that converts AWS API Gateway proxy events (payload formats 1.0 and 2.0, the latter also used by Lambda Function URLs) intoStandardLazyRequest, and writesStandardResponsethrough the streamawslambda.streamifyResponseprovides. Streaming bodies such as server-sent events now reach clients as they are produced instead of being buffered by the function.Behavior
httpMethodfield, and events typed with@types/aws-lambdaare accepted directly (verified by type tests).awslambda.HttpResponseStreammetadata prelude; multipleset-cookievalues survive through the dedicatedcookiesfield.standard-server→content-type→content-lengthpriority), so the same request resolves to the sameStandardBodyon every adapter.cookieheader, and format 1.0 query strings are re-encoded; 2.0'srawQueryStringpasses through untouched.awslambdaglobal is described by the exportedAwsLambdaGlobaltype and declared module-locally inside the adapter.Also included
@standardserver/node:canWriteToNodeResponseandgetNodeResponseErrornow check both the response and its underlying http2 stream instead of trusting only the inner stream (separate commit).Testing
@types/aws-lambda(dev-dependency only); package coverage is 100% on statements, branches, functions, and lines.