Skip to content

feat: deployment adapter for AWS Lambda#318

Merged
lazarv merged 5 commits intomainfrom
feat/adapter-aws
Mar 1, 2026
Merged

feat: deployment adapter for AWS Lambda#318
lazarv merged 5 commits intomainfrom
feat/adapter-aws

Conversation

@lazarv
Copy link
Owner

@lazarv lazarv commented Mar 1, 2026

This PR adds a new built-in AWS Lambda deployment adapter to @lazarv/react-server, enabling users to deploy their React Server applications to AWS with a single configuration change. The adapter leverages AWS SAM (Serverless Application Model) to provision a Lambda function with streaming support and an optional CloudFront CDN distribution.

Motivation

AWS Lambda is one of the most widely used serverless platforms. Until now, the aws option in create-react-server was marked as "coming soon." This PR delivers the full implementation, completing the AWS deployment story alongside the existing Vercel, Netlify, Cloudflare, Azure, Bun, and Deno adapters.

What's Included

AWS Lambda Adapter (packages/react-server/adapters/aws/index.mjs)

The core adapter that hooks into the react-server build pipeline:

  • Edge build mode — bundles the server into a single file optimized for Lambda deployment.
  • Static file bundling — copies all static assets (pre-rendered HTML, client components, public files, build assets) into the Lambda deployment package and generates a build-time manifest (static-manifest.json) for O(1) lookups at runtime.
  • SAM template generation — produces a template.json with:
    • An AWS::Serverless::Function resource configured with Function URL in RESPONSE_STREAM invoke mode for streaming SSR.
    • A custom AWS::CloudFront::CachePolicy that defers to origin Cache-Control headers (DefaultTTL/MinTTL = 0, MaxTTL = 1 year for immutable assets).
    • A AWS::CloudFront::Distribution with a single Lambda origin — all requests (static and dynamic) flow through one origin, avoiding CloudFront Function size limits, Origin Group failover issues, and hardcoded path patterns.
  • Configurable optionsname, stackName, runtime, memorySize, timeout, architecture, authType, environment, functionProperties, cloudfront, resources, outputs, template, and deployArgs.
  • Deploy command — exposes a sam deploy --guided command for first-time guided deployment.

Lambda Function Handler (packages/react-server/adapters/aws/functions/handler.mjs)

The runtime handler that executes inside Lambda:

  • Static file serving — intercepts GET requests and serves files from the bundled static manifest with appropriate Cache-Control headers:
    • Build assets (/assets/, /client/): public, max-age=31536000, immutable
    • HTML / x-component: must-revalidate
    • Public files: public, max-age=600
  • SSR via react-server — all non-static requests (and all non-GET requests) are forwarded to the react-server edge handler.
  • Streaming support — uses awslambda.streamifyResponse() when available (Lambda Function URLs with RESPONSE_STREAM mode), falling back to buffered API Gateway v2 responses.
  • Request translation — converts Lambda events (API Gateway v2 / Function URL format) into standard Web Request objects, including cookie handling and base64-encoded body support.
  • Cookie forwarding — merges set-cookie headers from react-server's HTTP context into the response.
  • Error handling — returns 404 for unmatched routes and 500 with error details for server errors.

Documentation

  • English docs (docs/src/pages/en/(pages)/deploy/aws.mdx) — comprehensive guide covering prerequisites (AWS CLI, SAM CLI), installation, full configuration reference, build & deploy workflow, architecture overview, and advanced customization.
  • Japanese docs (docs/src/pages/ja/(pages)/deploy/aws.mdx) — translated version of the English documentation.
  • Adapters index pages (EN & JA) — updated to list AWS Lambda as a supported adapter with a note about SAM CLI requirements.

Scaffolding (packages/create-react-server/steps/deploy.mjs)

  • Removed the disabled: "(coming soon)" flag from the AWS option in the deployment step.
  • Added "AWS Lambda" to the adapter name map and .aws, template.json, samconfig.toml to the gitignore entries for the adapter.

Architecture

Viewer → CloudFront (edge cache) → Lambda Function URL (RESPONSE_STREAM)
                                          │
                                          ├── Static file? → Serve from disk (with Cache-Control)
                                          │                   → CloudFront caches at edge
                                          │
                                          └── Dynamic request → react-server SSR
                                                                → Stream response back

Key design decisions:

  • Single Lambda origin — all traffic goes through one Lambda function, avoiding CloudFront Function size limits (10KB), Origin Group failover limitations (GET/HEAD only), and hardcoded path patterns that could conflict with user routes.
  • Static files bundled in Lambda — eliminates the need for a separate S3 bucket origin. CloudFront caches static responses at the edge after the first request, so subsequent requests never hit Lambda.
  • Streaming by default — uses RESPONSE_STREAM invoke mode for real-time SSR streaming, with automatic fallback to buffered responses for API Gateway v2.

@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
react-server-docs b5a6046 Mar 01 2026, 03:52 PM

@lazarv lazarv merged commit dc6ee69 into main Mar 1, 2026
100 of 101 checks passed
@lazarv lazarv deleted the feat/adapter-aws branch March 1, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant