Skip to content
Home
Blog
Notes
Back to Blog

Part 1 of 6 · Tanstack Aws

TanStack Start with AWS Lambda Web Functions

November 30, 2026•9 min read

Run TanStack Start on Lambda Web Functions. CDK and CloudFront send assets to a private S3 bucket and every other request to the Node server.

Cover image for TanStack Start with AWS Lambda Web Functions
awscdklambdatanstackcloudfront

Table of Contents

  • Introduction
  • Disclaimer
  • Architecture
  • App build
  • CDK, the Web Function
  • CDK, CloudFront
  • Gotchas
  • Runtime model and limits
  • Compared with the 2025 setup
  • Others who did this
  • Results
  • Sources

Introduction

Deploy TanStack Start serverless on AWS put TanStack Start on a Lambda event function. Nitro's aws-lambda preset produced a handler, and a regional REST API with response streaming sat between CloudFront and that function.

Lambda Web Functions run a normal HTTP server. The runtime passes a host:port in AWS_LAMBDA_HTTP_ENDPOINT, your process listens there, and Lambda forwards HTTP to it. Start can use the same Node server it uses locally.

The working example is the tanstack-aws tag 2026-11-30-tanstack-start-with-aws-lambda-web-functions. On that tag the public webapp is still the event function. The admin frontend is the Web Function, and the snippets below come from it. The CDK app is aws-cdk-lib 2.278.0. WebFunction has been in the library since 2.276.0.

Disclaimer

Same scope as the 2025 post. This is the deployment shape, not a production hardening guide. It does not cover WAF rules, alarms, structured logging, or a pipeline. Add those on top.

Architecture

CloudFront is the only public entry.

  • /assets/* comes from a private S3 bucket through origin access control.
  • Every other path goes to the Web Function endpoint. CloudFront signs those requests with origin access control. There is no API Gateway.

CloudFront sends /assets to a private S3 bucket and every other path to a Lambda Web Function. Both origins use origin access control.

What the 2025 stack had, and this one does not:

  • The REST API and its streaming integration.
  • Nitro's aws-lambda handler.
  • A memory setting, reserved concurrency, and Lambda tracing on the server.

Root files such as the manifest are Start routes, so they fall through to the Web Function. Only /assets/* is a separate cache behavior.

App build

The admin app builds with Nitro's Node server preset. In Nitro 3, node is the alias of node_server. The Node.js preset writes .output/server/index.mjs and listens on NITRO_HOST and NITRO_PORT (or HOST and PORT).

Reference: apps/webapp-admin/vite.config.ts

// preset `node` is a stand-in until https://github.com/nitrojs/nitro/pull/4777 ships
// `aws-lambda-web`. Then switch preset to `aws-lambda-web` and delete the entry shim.
nitro({
  preset: "node",
  output: {
    dir: path.join(packageRoot, ".output"),
  },
}),

There is no built-in preset for Web Functions yet. nitrojs/nitro#4777 is the open pull request for aws-lambda-web. Until that ships, a small shim is the entry file.

Web Functions load index.js at the package root unless you set AWS_LAMBDA_NODEJS_ENTRYPOINT. The build still emits index.mjs, so a script copies the shim to .output/server/index.js, copies the helper beside it, and writes a package.json with "type": "module" so the shim can use import.

Reference: apps/webapp-admin/lambda-web-entry.js and apps/webapp-admin/scripts/install-lambda-web-entry.js

import { applyLambdaWebEndpoint } from "./lambda-web-endpoint.js";

applyLambdaWebEndpoint(process.env.AWS_LAMBDA_HTTP_ENDPOINT);

await import("./index.mjs");

AWS_LAMBDA_HTTP_ENDPOINT looks like host:port, including an IPv6 host. The helper parses that and points Nitro at it. Nitro reads NITRO_HOST and NITRO_PORT before HOST and PORT, so the helper sets both pairs.

Reference: apps/webapp-admin/lambda-web-endpoint.js

const { host, port } = listenAddressFromLambdaEndpoint(endpoint);
process.env.HOST = host;
process.env.HOSTNAME = host;
process.env.PORT = port;
process.env.NITRO_HOST = host;
process.env.NITRO_PORT = port;

Do not set the CDK entryPoint. That writes AWS_LAMBDA_NODEJS_ENTRYPOINT and would skip index.js.

CDK, the Web Function

WebFunction creates the function, one revision, and one endpoint. This tag uploads code with WebFunctionCode.fromAssetToProvidedBucket into a versioned, private, SSE-S3 bucket. The copy is a custom resource. The CDK asset bucket is encrypted with the bootstrap key, so the copy role is granted kms:Decrypt on alias/cdk-bootstrap-key.

Reference: apps/cdk-app/lib/constructs/WebappServerWebFunction.ts

Alias.fromAliasName(this, "CdkBootstrapKeyAlias", "alias/cdk-bootstrap-key").grantDecrypt(
  codeCopyRole,
);

this.webappServer = new WebFunction(this, "WebappServer", {
  code: WebFunctionCode.fromAssetToProvidedBucket(codeBucket, repoPath(serverAssetPath), {
    copyOptions: { role: codeCopyRole },
  }),
  webFunctionName: webFunctionNameWithStage(Stack.of(this).stackName, webFunctionNameSuffix),
  runtime: WebFunctionRuntime.of("nodejs26.x"),
  timeout: Duration.seconds(TIMEOUT_IN_SECONDS),
  environment,
  defaultEndpointAuth: WebFunctionAuthType.IAM_AUTH,
  defaultEndpoint: {
    maxEnvironments: webFunctionMaxEnvironmentsForStage(appStage),
    rateLimit: webFunctionRateLimitForStage(appStage),
  },
});

aws-cdk-lib 2.278.0 only has WebFunctionRuntime.NODEJS_24_X. nodejs26.x is a supported Web Function runtime, so the code uses WebFunctionRuntime.of('nodejs26.x') instead of waiting for a constant. The generated physical name drops the stage, so webFunctionNameWithStage keeps the stack name, which already includes the stage, inside the 64-character limit.

This version of WebFunction has no memorySize, no reserved concurrency, and no tracing property. The endpoint's maxEnvironments and rateLimit are the cost caps, and this tag sets both from the stage.

CDK, CloudFront

The asset bucket blocks public access. S3BucketOrigin.withOriginAccessControl is the S3 origin.

The Web Function origin is an HTTPS origin on the endpoint domain, with an origin access control of type lambda and signing behavior always-amz-auth. In CDK that is FunctionUrlOriginAccessControl plus Signing.SIGV4_ALWAYS_AMZ_AUTH. CloudFront rejects the other signing behaviors for this origin type. always-amz-auth signs in a CloudFront header and can still forward the viewer's Authorization header.

The Web Function resource policy grants lambda:InvokeWebFunctionEndpoint to cloudfront.amazonaws.com, with an aws:SourceArn condition for this distribution. endpoint.grants.invoke writes that statement.

Reference: apps/cdk-app/lib/constructs/WebappDistribution.ts

const defaultBehavior = {
  allowedMethods: AllowedMethods.ALLOW_ALL,
  cachePolicy: CachePolicy.CACHING_DISABLED,
  compress: false,
  origin,
  originRequestPolicy: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
  responseHeadersPolicy: ResponseHeadersPolicy.SECURITY_HEADERS,
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};

const staticAssetBehavior = {
  cachePolicy: CachePolicy.CACHING_OPTIMIZED,
  origin: s3BucketOrigin,
  viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};

/assets/* uses CachingOptimized. The default behavior uses CachingDisabled. Compression is off because CloudFront buffers the response when compression is on, which breaks streaming.

const webFunctionOac = new FunctionUrlOriginAccessControl(this, "WebFunctionOac", {
  signing: Signing.SIGV4_ALWAYS_AMZ_AUTH,
});

return new HttpOrigin(webappWebFunction.endpoint.domainName, {
  originAccessControlId: webFunctionOac.originAccessControlId,
});

IAM_AUTH is required for this. WebFunctionAuthType.APPLICATION_MANAGED does not check IAM, and the endpoint domain stays public even with CloudFront in front. The lock here comes from this setup, not from creating a Web Function.

Gotchas

The viewer Host header returns 404. The endpoint routes on Host and expects its own domain. Forwarding the CloudFront domain makes Lambda return 404 with lambda-web-error-type: Platform.InvalidEndpoint. Use AllViewerExceptHostHeader, not AllViewer.

Only always-amz-auth is accepted. Other origin-access signing behaviors are rejected for a Web Function origin. A regional endpoint uses SigV4. A global endpoint (hostname ending in .lambda-web.global.on.aws) uses SigV4a. This tag uses the home-region endpoint and SigV4.

POST works without x-amz-content-sha256. A caller who signs directly must send that header, or Lambda returns 403. For PUT, POST, and PATCH, CloudFront signs the origin request as UNSIGNED-PAYLOAD and ignores a viewer-supplied hash. The browser does not compute one. The body is not part of the signature. HTTPS covers it in transit.

Runtime model and limits

Each execution environment is fixed at 2 GB and 2 vCPUs. You do not set memorySize. There is no reserved concurrency and no Lambda active tracing. Lambda does not create X-Ray service segments for a Web Function. A caller-supplied X-Amzn-Trace-Id is passed through, and the process can send its own traces.

The endpoint caps cost with maxEnvironments (2 to 10,000, per Region) and rateLimit (requests per second, per Region). Above the rate limit, Lambda returns 429. The account vCPU quota can stop scale-out before maxEnvironments does.

One environment serves many requests at once. maxConcurrencyPerEnvironment defaults to 64 and can be set from 1 to 128. Lambda may run below that ceiling. The server is one process, so module globals are shared across requests, and blocking the event loop blocks the other requests on that environment.

A deploy publishes a new revision and shifts the endpoint to it. Lambda's cleanup target is 50 revisions per function. That is not a hard cap: the count can sit above 50 while a revision is still receiving traffic or while cleanup runs. Unused older revisions are deleted automatically. A revision that an endpoint still points at is kept.

Compared with the 2025 setup

2025 event functionThis Web Function
Extra front doorRegional REST API, response streamingNone
ServerNitro aws-lambda handlerNode server, same shape as local
ConcurrencyOne request per environmentUp to 64 requests per environment
I/O-bound SSRA waiting invocation still occupies an environmentOne environment keeps working during I/O, and CPU billing is for active CPU time
Bypass around CloudFrontThe execute-api URL had no authorizerIAM plus the distribution ARN

The 2025 LambdaRestApi is regional. That construct sets no authorizer, resource policy, WAF, or secret header, and the distribution does not add one. API Gateway then accepts calls on the execute-api hostname, which never goes through CloudFront. The WebappApi construct committed with that guide matches the snippet in the post.

Here the endpoint auth type is IAM_AUTH. CloudFront signs with origin access control, and the resource policy allows only this distribution. There is no shared secret to rotate. APPLICATION_MANAGED would remove that lock. WAF is still a CloudFront concern if you want IP, bot, or request-body rules. The endpoint domain does not attach a web ACL.

What you give up from API Gateway: throttling settings, usage plans, and API Gateway access logs. rateLimit is the replacement for a throttle, and it is not a usage plan. You also cannot pick a memory size or a reserved concurrency for the function.

Others who did this

Fullstack with Lambda Web Functions - The Amplify Killer? on AWS Builder Center deploys TanStack Start with the lambda-web-function-construct package. CloudFront, a private bucket, and always-amz-auth show up there too.

Ryuki Tobita compared SvelteKit, TanStack Start, and Next.js on Lambda Web Functions (16 October 2026). Each framework is a Node server plus a short entry file that maps AWS_LAMBDA_HTTP_ENDPOINT onto HOST and PORT.

Alchemy's TanStack Start guide deploys the SSR server as a Web Function and serves client assets from private S3 through CloudFront.

Results

tanstack-aws-examples.com is the public webapp. It still uses the old way: an Event Function and a REST API Gateway, as in the 2025 post. admin.tanstack-aws-examples.com is the admin subdomain, and that one is the Lambda Web Function.

Sources

  • Example tag: github.com/JohannesKonings/tanstack-aws
  • Announcement: Announcing AWS Lambda Web Functions
  • Building Lambda Web Functions with Node.js
  • Lambda quotas, including Web Function quotas
  • Endpoint access control
  • Scaling and revisions
  • Restrict access to a Lambda Web Function origin
  • CDK: aws_lambda.WebFunction
  • Nitro: Node.js server preset
  • Open preset pull request: nitrojs/nitro#4777

Published on November 30, 2026

Share:Bluesky Icon
← Previous: TanStack AI with AWS Bedrock on TanStack Start (simple example)Next →
Categories: aws

Related Posts

Feb 2, 2026

TanStack AI with AWS Bedrock on TanStack Start (simple example)

Jan 8, 2026

Using Server Sent Events (SSE) to sync Tanstack Db from AWS DynamoDB

Dec 27, 2025

Simple example of TanStack DB with DynamoDB on AWS with multiple entities

RSS|

© 2026 Johannes Konings. All rights reserved.