Summary
The current Lambda handler (bridge.js) spawns node server.js as a child process, waits for it to start (polling 50×100ms), then proxies HTTP requests. This adds ~2-5 seconds of cold start latency.
Current Architecture
Lambda invocation
→ bridge.js handler
→ spawn("node", ["server.js"]) // ~1-3s to start
→ poll 127.0.0.1:3000 (50 retries × 100ms) // ~2-5s
→ proxy request via http.request()
→ return response
Target Architecture (OpenNext-style)
Lambda invocation
→ index.mjs handler
→ import NextServer from ".next/standalone/server.js"
→ convert Lambda event to Node.js request
→ NextServer.handle(req, res)
→ convert response to Lambda format
→ return response
Benefits
- Cold start: ~5-10s → ~1.3s (eliminates subprocess + polling)
- Simpler code — no HTTP proxying between processes
- Better error handling — stack traces from Next.js are visible
- Memory efficiency — one Node.js process instead of two
Files to Modify
internal/packaging/serverless_packager.go — Replace bridge.js content with NextServer adapter
cli/internal/serverless/aws.go — Remove duplicate bridge.js (line 28)
cli/internal/serverless/aws_lambda.go — Update handler path to index.handler
References
Difficulty: Hard · Language: Go + JavaScript
Summary
The current Lambda handler (
bridge.js) spawnsnode server.jsas a child process, waits for it to start (polling 50×100ms), then proxies HTTP requests. This adds ~2-5 seconds of cold start latency.Current Architecture
Target Architecture (OpenNext-style)
Benefits
Files to Modify
internal/packaging/serverless_packager.go— Replace bridge.js content with NextServer adaptercli/internal/serverless/aws.go— Remove duplicate bridge.js (line 28)cli/internal/serverless/aws_lambda.go— Update handler path toindex.handlerReferences
bridge.jsinserverless_packager.goline 209Difficulty: Hard · Language: Go + JavaScript