Lambda was never the wrong place for APIs. One request per box was.
If you are building a Node.js API, Lambda usually is not on the list. You reach for a container on ECS, or an instance on EC2. On 12 October 2026 AWS launched Lambda Web Functions, and the reasons behind that instinct need a second look.
Why the instinct was right
The instinct was never superstition. Classic Lambda, which AWS now calls Event Functions, had three properties that fought against a normal web server.
- It wanted a handler, not a server. Your code was a function,
handler(event, context), that Lambda called once per request. An Express app expects to own a port and a request loop, so it needed an adapter library to translate Lambda events into HTTP requests and back. - One request per environment. An execution environment is the small, isolated virtual machine that runs your code. In classic Lambda, each environment handles exactly one request at a time. A hundred requests at the same moment means a hundred environments.
- Wall-clock billing. You pay for memory multiplied by how long each request runs, from start to finish, whether your code is computing or sitting idle.
For a typical CRUD API that answers in 100 ms, these costs are small. For the apps most teams are building right now, they are not.
The whole argument in under a minute. Numbers in the video are illustrative, not measured.
Why it hurt most for AI apps and agents
An AI app's request is mostly waiting. Your server sends a prompt to the model, then relays tokens back to the user as they arrive. A streamed answer can easily run 15 to 20 seconds (illustrative). An agent run takes longer, because it loops: call the model, call a tool, call the model again with the result.
During all of that, your Node.js process does very little. It parses some JSON, forwards a few bytes, and waits for the next chunk. Most of the time is spent waiting on someone else's server.
Classic Lambda billed that waiting in full. Twenty seconds of streaming was twenty seconds of memory, billed per millisecond. And because each environment held one request, a hundred users talking to your agent at once needed a hundred environments, nearly all of them idle.
That is the real mismatch. Lambda was fine at running code. It was a poor fit for a workload that is 95% waiting (illustrative), because it gave every waiting request its own box and charged for the whole wait.
What Web Functions change
Web Functions are a second type of Lambda function. You deploy a normal HTTP server, and one environment serves many requests at once. AWS renamed the existing kind to Event Functions; they keep working unchanged.
- A normal server. Express, Fastify, Hono or Next.js (for server-side rendered, or SSR, apps) run as they are, listening on a port. No handler, no adapter.
- Many requests per environment. The setting
maxConcurrencyPerEnvironmentdefaults to 64 and goes up to 128. It is a ceiling: Lambda starts a new function at a conservative limit and adjusts it as it learns your resource usage. - Active CPU billing. You pay for CPU time your code actually uses, plus the memory each environment consumes for as long as it runs, plus requests. Waiting on the model costs CPU almost nothing.
- Streaming built in. Server-sent events and chunked responses work without extra configuration.
- Multi-Region with one command. Add
--regionsto the deploy command and Lambda copies your code to each Region behind one global URL with latency-based routing. - Canary releases. Every deploy creates an immutable revision. An endpoint can split traffic across two revisions, for example 90% and 10%.
At launch, every environment is the same size: Node.js 24 on Arm64, 2 vCPUs and 2 GB of memory.
A minimal Express server
The only Lambda-specific line reads AWS_LAMBDA_HTTP_ENDPOINT. Lambda sets it to the host:port your server must listen on. On your laptop it is unset, so the code falls back to a local port.
// index.js - Web Functions load index.js from the package root by default const express = require('express'); const app = express(); app.use(express.json()); app.get('/health', (req, res) => res.json({ ok: true })); // A streaming route, shaped like an AI response app.get('/stream', async (req, res) => { res.setHeader('Content-Type', 'text/event-stream'); res.setHeader('Cache-Control', 'no-cache'); let closed = false; req.on('close', () => { closed = true; }); // stop work if the client leaves for (const word of ['one', 'environment', 'many', 'requests']) { if (closed) return; res.write(`data: ${word}\n\n`); await new Promise((r) => setTimeout(r, 500)); // stands in for waiting on the model } res.end(); }); // Lambda sets this to "host:port"; locally it is unset const [host, port] = (process.env.AWS_LAMBDA_HTTP_ENDPOINT || '127.0.0.1:3000').split(':'); app.listen(Number(port), host, () => console.log(`listening on ${host}:${port}`)); // Lambda sends SIGTERM before removing an environment; you get up to 1 second process.on('SIGTERM', () => process.exit(0)); Deploying it is one command: aws lambda-web deploy --name my-api --code ., which bundles the code, creates a revision and an endpoint, and returns an HTTPS URL.
Two rules from the docs matter here. The server must start listening within 10 seconds, so do slow setup after listen(). And while the 500 ms wait runs, the same environment is free to serve other requests. That last point is also where the first bug appears.
The bug a shared environment exposes
Code written for classic Lambda often keeps per-request data in a module-level variable. That was safe there, because one environment never ran two requests at the same time. In a Web Function it can return one user's data to another.
let ctx = {}; // BUG: one object shared by every request in this environment app.use(async (req, res, next) => { ctx.user = await authenticate(req); next(); }); app.post('/agent', async (req, res) => { const plan = await callModel(req.body.prompt); // other requests run during this wait const account = await fetchAccount(ctx.user.id); // ctx.user may now be someone else res.json({ plan, account }); }); Here is what happens. Alice's request sets ctx.user to Alice, then waits on the model. While it waits, Bob's request arrives in the same environment and sets ctx.user to Bob. When Alice's model call returns, her request reads ctx.user and fetches Bob's account.
Node.js runs one request's code at a time, so there is no data race in the threading sense. The problem is that every await hands the process to other requests, and a shared variable can change before you come back. Send three staggered requests to this code on your laptop and all three users get the last user's account.
The fix
Keep per-request data on the request. In Express, res.locals exists for this.
app.use(async (req, res, next) => { res.locals.user = await authenticate(req); next(); }); app.post('/agent', async (req, res) => { const user = res.locals.user; // belongs to this request only const plan = await callModel(req.body.prompt); const account = await fetchAccount(user.id); res.json({ plan, account }); }); If the user is needed deep inside helper functions, Node's built-in AsyncLocalStorage gives each request its own context that survives across await, without passing it through every call.
What can stay global: database connection pools, SDK clients and read-only configuration. Keep any shared cache bounded, because 64 requests share one 2 GB environment.
The second trap is CPU. Node.js has one main thread. A request that spends 300 ms parsing a huge document or hashing a password blocks every other request in that environment for those 300 ms. AWS's guidance is to move such work to worker_threads or lower maxConcurrencyPerEnvironment.
What one 20-second agent request costs
At steady load, a 20-second streaming agent request costs about 25 times less on a Web Function than on a classic Lambda, using AWS's published prices. The catch is the word steady.
Prices below are from the AWS Lambda pricing page for US East (N. Virginia), Arm, free tier excluded, data transfer excluded.
| Price | Event Function (classic) | Web Function |
|---|---|---|
| Requests | $0.20 per million | $0.30 per million |
| Compute | $0.0000133334 per GB-second of configured memory, for the full duration | $0.0000276944 per vCPU-second of CPU actually used |
| Memory | Included in the line above | $0.0000036667 per GB-second consumed by the environment, for as long as it runs |
The request is illustrative: 20 seconds end to end, 0.3 seconds of real CPU work, 1 GB configured on the classic function, and about 0.5 GB consumed by the Web Function environment.
Classic Event Function: 20 s × 1 GB × $0.0000133334 + $0.0000002 = $0.000267 per request, or about $267 per million. You pay for all 20 seconds.
Web Function: the request and CPU charges are fixed. Request: $0.0000003. CPU: 0.3 s × $0.0000276944 = $0.0000083. Memory is billed to the environment, not the request, so each request's share depends on how many others are in flight with it.
| Scenario (illustrative) | Memory share | Total per request | Per million |
|---|---|---|---|
| 20 requests in flight share one environment | $0.0000018 | $0.0000104 | $10.44 |
| The request is alone in its environment | $0.0000367 | $0.0000453 | $45.28 |
| Alone, then the environment idles 5 minutes before removal | $0.000587 | $0.000595 | More than 2x classic |
The first two rows are the story: the wait is nearly free, and sharing makes memory nearly free too. The third row is the trap. AWS bills memory for the environment's whole life, including time between requests, and the docs do not say how long an idle environment survives. One independent test saw idle environments removed after roughly five minutes. For a trickle of isolated requests, that idle tail can cost more than the classic function did.
AWS's own pricing page has a worked example that matches the busy case: an AI streaming endpoint with 5 million requests a month, 3 seconds each, 200 ms of CPU and 0.5 GB of memory, comes to $33.94 per month on Web Functions. The same traffic on a classic Arm function configured at 0.5 GB would be about $101 by the same arithmetic.
The Web Functions billing model is published in full, so none of this needs guessing. What you cannot know upfront is your own CPU time per request and how many requests share an environment, so measure both before you trust any per-request number, including these.
When not to use it
Web Functions fit spiky, wait-heavy Node.js traffic. Several workloads still belong on ECS, EKS or EC2.
- Flat, high traffic around the clock. Per unit, Web Functions cost more than containers. An active vCPU-hour costs about $0.0997 against $0.0324 for an Arm vCPU-hour on Fargate, and memory costs about $0.0132 per GB-hour against $0.0036. Fargate bills what you allocate whether you use it or not, while Web Functions bill what you use. As a rough rule, if a service would keep its CPUs more than about a third busy all day, a well-sized container is likely cheaper on compute alone. Add the load balancer a container needs before you decide.
- CPU-heavy work. One environment runs one Node.js main thread for up to 128 requests. Image processing, large PDF parsing or heavy crypto in the request path slows everyone sharing that environment.
- Anything other than Node.js. At launch the only runtime is Node.js 24. Java and Spring Boot services stay on containers or on Event Functions with SnapStart, which restores a pre-started JVM snapshot to shorten startup.
- WebSockets. Endpoints speak HTTP/1.1 only and strip the
Upgradeheader, and the docs state WebSocket upgrades are not supported. Server-sent events work for one-way streaming; two-way real-time traffic needs ECS or API Gateway WebSockets. - Strict first-request latency. There is no minimum or reserved environment setting. After a quiet period the endpoint scales to zero, and the next request waits while a new environment starts up (a cold start).
- Region and network needs. At launch you can create Web Functions in five Regions: N. Virginia, Ohio, Oregon, Tokyo and Ireland. Custom domains and AWS WAF need CloudFront in front. Private VPC access works only on single-Region endpoints, not multi-Region ones.
- Long-lived state or background jobs that must finish. Lambda can remove an environment at any time and gives the process up to 1 second after
SIGTERM. Keep anything important in DynamoDB, S3 or a queue.
Decision guide
Start from the traffic shape and the runtime, not from the service name.
| Choose | When the workload is | Watch out for |
|---|---|---|
| Web Function | A Node.js API, backend-for-frontend, SSR app or AI streaming endpoint with variable or spiky traffic that spends most of each request waiting | Shared state across requests, CPU-heavy code, idle memory cost, five launch Regions |
| Event Function | Queue consumers, S3, EventBridge or DynamoDB stream triggers, scheduled jobs, or any runtime other than Node.js | Wall-clock billing on long waits, one request per environment |
| ECS, EKS or EC2 | Java or Spring Boot services, WebSockets, flat high traffic, strict latency with no cold starts, GPUs, or full control of the OS and network | You run and pay for capacity whether traffic arrives or not |
The real constraint
The old advice said Node.js APIs do not belong on Lambda. Look at what changed, and the advice turns out to be about one design choice: giving every request its own environment and billing it for every second it waited. Web Functions keep the parts of Lambda people liked, scale to zero, no servers and fast scaling, and drop that one choice.
It does not make ECS obsolete. It moves the line between them. Wait-heavy, spiky Node.js traffic now has a serverless home; flat, CPU-heavy or non-Node traffic still belongs on containers.
Lambda was never the wrong place for APIs. One request per box was.
Sources
- Announcing AWS Lambda Web Functions (AWS News Blog, 12 Oct 2026)
- Exploring AWS Lambda Web Functions for building web applications (AWS Compute Blog)
- Lambda Web Function runtimes
- Scaling behavior for Lambda Web Functions
- Execution environment lifecycle
- HTTP requests and responses
- Configuring networking for Lambda Web Functions
- AWS Lambda pricing
- AWS Fargate pricing
- Some notes on Lambda Web Functions (Aidan Steele)