<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prateek Thakur</title>
    <description>The latest articles on DEV Community by Prateek Thakur (@prateekthakur).</description>
    <link>https://dev.to/prateekthakur</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4247966%2F05052c74-eb55-4b04-8fce-76740c71d011.jpg</url>
      <title>DEV Community: Prateek Thakur</title>
      <link>https://dev.to/prateekthakur</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prateekthakur"/>
    <language>en</language>
    <item>
      <title>AWS Lambda Web Functions vs Classic Lambda vs EC2/ECS</title>
      <dc:creator>Prateek Thakur</dc:creator>
      <pubDate>Mon, 16 Nov 2026 15:01:44 +0000</pubDate>
      <link>https://dev.to/prateekthakur/aws-lambda-web-functions-vs-classic-lambda-vs-ec2ecs-2808</link>
      <guid>https://dev.to/prateekthakur/aws-lambda-web-functions-vs-classic-lambda-vs-ec2ecs-2808</guid>
      <description>&lt;p&gt;&lt;strong&gt;Lambda was never the wrong place for APIs. One request per box was.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the instinct was right
&lt;/h2&gt;

&lt;p&gt;The instinct was never superstition. Classic Lambda, which AWS now calls &lt;strong&gt;Event Functions&lt;/strong&gt;, had three properties that fought against a normal web server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It wanted a handler, not a server.&lt;/strong&gt; Your code was a function, &lt;code&gt;handler(event, context)&lt;/code&gt;, 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One request per environment.&lt;/strong&gt; An &lt;em&gt;execution environment&lt;/em&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wall-clock billing.&lt;/strong&gt; You pay for memory multiplied by how long each request runs, from start to finish, whether your code is computing or sitting idle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/5KIkXjU_YiQ" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The whole argument in under a minute. Numbers in the video are illustrative, not measured.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it hurt most for AI apps and agents
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Web Functions change
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A normal server.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Many requests per environment.&lt;/strong&gt; The setting &lt;code&gt;maxConcurrencyPerEnvironment&lt;/code&gt; defaults 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Active CPU billing.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streaming built in.&lt;/strong&gt; Server-sent events and chunked responses work without extra configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Region with one command.&lt;/strong&gt; Add &lt;code&gt;--regions&lt;/code&gt; to the deploy command and Lambda copies your code to each Region behind one global URL with latency-based routing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Canary releases.&lt;/strong&gt; Every deploy creates an immutable &lt;em&gt;revision&lt;/em&gt;. An endpoint can split traffic across two revisions, for example 90% and 10%.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At launch, every environment is the same size: Node.js 24 on Arm64, 2 vCPUs and 2 GB of memory.&lt;/p&gt;

&lt;h3&gt;
  
  
  A minimal Express server
&lt;/h3&gt;

&lt;p&gt;The only Lambda-specific line reads &lt;code&gt;AWS_LAMBDA_HTTP_ENDPOINT&lt;/code&gt;. Lambda sets it to the &lt;code&gt;host:port&lt;/code&gt; your server must listen on. On your laptop it is unset, so the code falls back to a local port.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js - Web Functions load index.js from the package root by default&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'express'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/health'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// A streaming route, shaped like an AI response&lt;/span&gt;
&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/stream'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Content-Type'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'text/event-stream'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Cache-Control'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'no-cache'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;closed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'close'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;closed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// stop work if the client leaves&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'one'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'environment'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'many'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'requests'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;closed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`data: ${word}\n\n`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// stands in for waiting on the model&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Lambda sets this to "host:port"; locally it is unset&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;AWS_LAMBDA_HTTP_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;'127.0.0.1:3000'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`listening on ${host}:${port}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Lambda sends SIGTERM before removing an environment; you get up to 1 second&lt;/span&gt;
&lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SIGTERM'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploying it is one command: &lt;code&gt;aws lambda-web deploy --name my-api --code .&lt;/code&gt;, which bundles the code, creates a revision and an endpoint, and returns an HTTPS URL.&lt;/p&gt;

&lt;p&gt;Two rules from the docs matter here. The server must start listening within 10 seconds, so do slow setup after &lt;code&gt;listen()&lt;/code&gt;. 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug a shared environment exposes
&lt;/h2&gt;

&lt;p&gt;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.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// BUG: one object shared by every request in this environment&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/agent'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;callModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// other requests run during this wait&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ctx.user may now be someone else&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what happens. Alice's request sets &lt;code&gt;ctx.user&lt;/code&gt; to Alice, then waits on the model. While it waits, Bob's request arrives in the same environment and sets &lt;code&gt;ctx.user&lt;/code&gt; to Bob. When Alice's model call returns, her request reads &lt;code&gt;ctx.user&lt;/code&gt; and fetches Bob's account.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;await&lt;/code&gt; 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.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix
&lt;/h3&gt;

&lt;p&gt;Keep per-request data on the request. In Express, &lt;code&gt;res.locals&lt;/code&gt; exists for this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;locals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/agent'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;locals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="c1"&gt;// belongs to this request only&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;callModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetchAccount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the user is needed deep inside helper functions, Node's built-in &lt;code&gt;AsyncLocalStorage&lt;/code&gt; gives each request its own context that survives across &lt;code&gt;await&lt;/code&gt;, without passing it through every call.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;worker_threads&lt;/code&gt; or lower &lt;code&gt;maxConcurrencyPerEnvironment&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What one 20-second agent request costs
&lt;/h2&gt;

&lt;p&gt;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 &lt;em&gt;steady&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Prices below are from the &lt;a href="https://aws.amazon.com/lambda/pricing/" rel="noopener noreferrer"&gt;AWS Lambda pricing page&lt;/a&gt; for US East (N. Virginia), Arm, free tier excluded, data transfer excluded.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Price&lt;/th&gt;
&lt;th&gt;Event Function (classic)&lt;/th&gt;
&lt;th&gt;Web Function&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Requests&lt;/td&gt;
&lt;td&gt;$0.20 per million&lt;/td&gt;
&lt;td&gt;$0.30 per million&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compute&lt;/td&gt;
&lt;td&gt;$0.0000133334 per GB-second of configured memory, for the full duration&lt;/td&gt;
&lt;td&gt;$0.0000276944 per vCPU-second of CPU actually used&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory&lt;/td&gt;
&lt;td&gt;Included in the line above&lt;/td&gt;
&lt;td&gt;$0.0000036667 per GB-second consumed by the environment, for as long as it runs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Classic Event Function:&lt;/strong&gt; 20 s × 1 GB × $0.0000133334 + $0.0000002 = &lt;strong&gt;$0.000267 per request&lt;/strong&gt;, or about $267 per million. You pay for all 20 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web Function:&lt;/strong&gt; 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.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario (illustrative)&lt;/th&gt;
&lt;th&gt;Memory share&lt;/th&gt;
&lt;th&gt;Total per request&lt;/th&gt;
&lt;th&gt;Per million&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20 requests in flight share one environment&lt;/td&gt;
&lt;td&gt;$0.0000018&lt;/td&gt;
&lt;td&gt;$0.0000104&lt;/td&gt;
&lt;td&gt;$10.44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The request is alone in its environment&lt;/td&gt;
&lt;td&gt;$0.0000367&lt;/td&gt;
&lt;td&gt;$0.0000453&lt;/td&gt;
&lt;td&gt;$45.28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alone, then the environment idles 5 minutes before removal&lt;/td&gt;
&lt;td&gt;$0.000587&lt;/td&gt;
&lt;td&gt;$0.000595&lt;/td&gt;
&lt;td&gt;More than 2x classic&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;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. &lt;a href="https://awsteele.com/blog/2026/10/12/some-notes-on-lambda-web-functions.html" rel="noopener noreferrer"&gt;One independent test&lt;/a&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to use it
&lt;/h2&gt;

&lt;p&gt;Web Functions fit spiky, wait-heavy Node.js traffic. Several workloads still belong on ECS, EKS or EC2.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Flat, high traffic around the clock.&lt;/strong&gt; 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 &lt;a href="https://aws.amazon.com/fargate/pricing/" rel="noopener noreferrer"&gt;Fargate&lt;/a&gt;, 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CPU-heavy work.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything other than Node.js.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WebSockets.&lt;/strong&gt; Endpoints speak HTTP/1.1 only and strip the &lt;code&gt;Upgrade&lt;/code&gt; header, 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict first-request latency.&lt;/strong&gt; 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).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Region and network needs.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long-lived state or background jobs that must finish.&lt;/strong&gt; Lambda can remove an environment at any time and gives the process up to 1 second after &lt;code&gt;SIGTERM&lt;/code&gt;. Keep anything important in DynamoDB, S3 or a queue.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Decision guide
&lt;/h2&gt;

&lt;p&gt;Start from the traffic shape and the runtime, not from the service name.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Choose&lt;/th&gt;
&lt;th&gt;When the workload is&lt;/th&gt;
&lt;th&gt;Watch out for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Web Function&lt;/td&gt;
&lt;td&gt;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&lt;/td&gt;
&lt;td&gt;Shared state across requests, CPU-heavy code, idle memory cost, five launch Regions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Event Function&lt;/td&gt;
&lt;td&gt;Queue consumers, S3, EventBridge or DynamoDB stream triggers, scheduled jobs, or any runtime other than Node.js&lt;/td&gt;
&lt;td&gt;Wall-clock billing on long waits, one request per environment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ECS, EKS or EC2&lt;/td&gt;
&lt;td&gt;Java or Spring Boot services, WebSockets, flat high traffic, strict latency with no cold starts, GPUs, or full control of the OS and network&lt;/td&gt;
&lt;td&gt;You run and pay for capacity whether traffic arrives or not&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The real constraint
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Lambda was never the wrong place for APIs. One request per box was.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/aws/announcing-aws-lambda-web-functions-for-fast-consistent-web-app-performance-anywhere/" rel="noopener noreferrer"&gt;Announcing AWS Lambda Web Functions (AWS News Blog, 12 Oct 2026)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/compute/exploring-aws-lambda-web-functions-for-building-web-applications/" rel="noopener noreferrer"&gt;Exploring AWS Lambda Web Functions for building web applications (AWS Compute Blog)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/web-functions-runtimes.html" rel="noopener noreferrer"&gt;Lambda Web Function runtimes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/web-functions-scaling.html" rel="noopener noreferrer"&gt;Scaling behavior for Lambda Web Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/web-functions-env-lifecycle.html" rel="noopener noreferrer"&gt;Execution environment lifecycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/web-functions-http.html" rel="noopener noreferrer"&gt;HTTP requests and responses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/web-functions-networking.html" rel="noopener noreferrer"&gt;Configuring networking for Lambda Web Functions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/lambda/pricing/" rel="noopener noreferrer"&gt;AWS Lambda pricing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/fargate/pricing/" rel="noopener noreferrer"&gt;AWS Fargate pricing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://awsteele.com/blog/2026/10/12/some-notes-on-lambda-web-functions.html" rel="noopener noreferrer"&gt;Some notes on Lambda Web Functions (Aidan Steele)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>serverless</category>
      <category>node</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
