
Fullstack with Lambda Web Functions - The Amplify Killer?
Lambda Web Functions run Node.js under the hood and thus let you run an HTTP server. I wonder if it would be possible to run a Next.js or TanStack Start application. In this blog post, I will show you how to run your TanStack app with CloudFront and answer whether Lambda Web Functions are the Amplify Killer.
Series: AWS Lambda Webfunctions (4 articles)
- …
- 4Fullstack with Lambda Web Functions - The Amplify Killer? This article
AI helped me with Grammar, sentences, and code examples. However, the structure and idea are my own.
What if I told you you could bring your (TypeScript/JavaScript) full-stack app to Lambda?
Yes? Yes! Really!
Let me show you how!
Lambda Web Functions recap
AWS recently released Lambda Web Functions , which lets you bring backend frameworks like Express or Hono to Lambda with no code changes. That means AWS now divides Lambda into event-based (the old way) and web-based functions.
But can we also run NextJS, TanStack Start, or a Nuxt App? How can we serve static files such as HTML, CSS, and JS in Lambda?
Adding CloudFront into the Mix
It is nothing new; AWS already wrote about how to serve static files with CloudFront and AWS Lambda .
In the Next.js example, CloudFront is served from a private Bucket that contains the built and static files.

This also applies to other frameworks.
Framework | Construct source | Static directory inside the artifact | CloudFront path |
|---|---|---|---|
Next.js standalone | NextJsWebFunction | .next/static/ | /_next/static/* |
Astro SSR ( @astrojs/node ) | AstroWebFunction | dist/client/_astro/ | /_astro/* |
Nuxt (Nitro node-server ) | NuxtWebFunction | .output/public/_nuxt/ | /_nuxt/* |
TanStack Start | TanStackWebFunction | dist/client/assets/ | /assets/* |
Unlike the Event Lambda, it doesn't need an API Gateway or a "special" endpoint to serve static files.
Adding it to AWS CDK
If you have followed my previous blog in this series, I have created a Lambda Web Function construct .
We need to add a CloudFront distribution to deliver and route traffic to the website.
import { Distribution } from "aws-cdk-lib/aws-cloudfront";
new Distribution(this, "Distribution", { defaultBehavior: { origin: webFunctionOrigin, // ... }, additionalBehaviors,});
It creates an AWS resource with a hostname such as:
https://d123example.cloudfront.net
For NextJS, it routes requests like this:
https://d123example.cloudfront.net/_next/static/chunk.js → private S3 bucket
https://d123example.cloudfront.net/dashboard → Web Function → Next.js server
The distribution also defines caching, allowed HTTP methods, HTTPS requirements,
response headers, and origin access controls.
Before that, we need to define the origin, which is the Web Functions endpoint. “Origin” means the backend CloudFront fetches content from—here, our Web Function. The Web Function endpoint requires IAM authentication. CloudFront therefore needs to sign requests before forwarding them:
Browser │ Normal HTTPS request ▼ CloudFront │ AWS SigV4-signed HTTPS request ▼ IAM-protected Web Function
The browser doesn’t need AWS credentials. CloudFront authenticates its own request to the backend.
import { Distribution, OriginProtocolPolicy } from "aws-cdk-lib/aws-cloudfront";import { HttpOrigin, S3BucketOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
const webFunction = new WebFunction(/* props */)
const webFunctionOriginAccessControl = new CfnOriginAccessControl( this, "WebFunctionOriginAccessControl", { originAccessControlConfig: { name: Names.uniqueResourceName(this, { maxLength: 64 }), description: "Signs CloudFront requests to the Web Function endpoint", originAccessControlOriginType: "lambda", signingBehavior: "always-amz-auth", signingProtocol: "sigv4", }, }, );
const webFunctionOrigin = new HttpOrigin(webFunction.endpointDomainName, { originAccessControlId: webFunctionOriginAccessControl.attrId, protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,});
Creating an Origin Access Control (OAC) alone does nothing until an origin references it. Signing and permission are separate.
OAC handles authentication—signing the request. The Web Function’s resource policy handles authorization — allowing that request.
Your code grants:
Principal: { Service: "cloudfront.amazonaws.com" }, Action: "lambda: InvokeWebFunctionEndpoint", Resource: webFunction.endpointArn, Condition: { StringEquals: { "aws: SourceArn": this.distribution.distributionArn, }, },
Together:
- OAC: “CloudFront signs the origin request.”
- Resource policy: “This particular CloudFront distribution is allowed to invoke the endpoint.”
This is not user authentication: it protects the CloudFront-to-backend connection. Your app still needs its own login and authorization where appropriate.
Custom CDK Constructs
To simplify the process, I wrote several CDK constructs to deploy your NextJS, Nuxt, Astro, and Tanstack app. All you need to provide is your app and the build output path in
artifactDirectory . Each Construct also offers a permissions property that allows the Web Function to access other AWS Services.
import { AstroWebFunction, NextJsWebFunction } from "lambda-web-function-construct";
// Inside your CDK stack, choose the construct for the artifact you built.const nextSite = new NextJsWebFunction(this, "NextSite", { artifactDirectory: ".next/static/", functionName: "my-nextjs-site",});
const astroSite = new AstroWebFunction(this, "AstroSite", { artifactDirectory: "dist/client/_astro/", functionName: "my-astro-site",});
const nuxtSite = new NuxtWebFunction(this, "NuxtSite", { artifactDirectory: ".output/public/_nuxt/", functionName: "my-nuxt-site",});
const tanstackSite = new TanstackWebFunction(this, "TanstackSite", { artifactDirectory: "dist/client/assets/", functionName: "my-tanstack-site",});
Is it an Amplify Killer?
Amplify has many features, such as Amplify Hosting , including CI/CD. You connect your GitHub repository, and it deploys whenever you push to main. It also comes with an Amplify Dashboard for observability.
But if you want to use Next.js in Amplify, you need to use Amplify's Adapter/SDK. The SDK offers UI components and an easier way to specify your data model.
You can easily integrate AWS services into your Amplify app, whereas with Web Functions, you would write the glue code yourself.
However, using Web Functions makes your Fullstack App portable. A Next.js or TanStack app would also work in a container or on a different cloud provider. So you don't need to know the Amplify SDK, and the learning curve is lower (if that even matters in the age of AI).
In my part 2 , where I also compared the prices, Web Functions would cost much less than Amplify. Because they still use the traditional way of services. Eventually, they will move to Web Functions.
Lambda Web Functions won't kill Amplify, because the thing people buy from Amplify — the managed workflow — is exactly the thing Web Functions deliberately don't provide. What they can kill is the idea that running a full web framework on serverless AWS requires either a platform tax or an event-handler rewrite. For teams whose AWS footprint is already deep, the web tier just became another construct in the stack.
And if you want to try it:
npm install lambda-web-function-construct , point NextJsWebFunction at your .next directory, and you're deploying your own infrastructure.Series: AWS Lambda Webfunctions (4 articles)
- …
- 4Fullstack with Lambda Web Functions - The Amplify Killer? This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article