[{"data":1,"prerenderedAt":97},["ShallowReactive",2],{"pattern-lambda-web-http-server-nodejs-sam":3,"pattern-group-lambda-web-http-server-nodejs-sam":72},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":10,"deploy":12,"description":15,"extension":16,"framework":17,"gitHub":18,"highlight":22,"introBox":23,"language":31,"level":32,"meta":33,"patternArch":34,"patternGroup":55,"patternGroupLabel":6,"resources":56,"stem":67,"testing":68,"videoId":6,"__hash__":71},"patterns\u002Fpatterns\u002Flambda-web-http-server-nodejs-sam.json","Node.js HTTP server on AWS Lambda Web Functions",null,{"text":8},[9],"Delete the stack: \u003Ccode>sam delete --stack-name lambda-web-http-server-sam\u003C\u002Fcode>.",[11],"content\u002Fcontributors\u002Fjon-loinaz-anton.json",{"text":13},[14],"See the GitHub repo for deployment instructions.","Run a zero-dependency Node.js http.createServer app as a Lambda Web Function with a public HTTPS endpoint, using AWS SAM.","json","AWS SAM",{"template":19},{"patternPath":20,"templateFile":21},"lambda-web-http-server\u002Fnodejs\u002Fsam","template.yaml","true",{"headline":24,"text":25},"How it works",[26,27,28,29,30],"This pattern deploys the smallest possible Lambda Web Function: a Node.js server built with the standard \u003Ccode>http\u003C\u002Fcode> module and no dependencies. Lambda Web Functions run a long-lived HTTP server inside a Firecracker microVM and forward requests to it directly, so the code has no Lambda handler, no event object and no response mapping. The same \u003Ccode>index.js\u003C\u002Fcode> runs locally with \u003Ccode>node index.js\u003C\u002Fcode> and on AWS without changes.","The application reads the address it must listen on from the \u003Ccode>AWS_LAMBDA_HTTP_ENDPOINT\u003C\u002Fcode> environment variable, which the runtime sets to \u003Ccode>0.0.0.0:3000\u003C\u002Fcode>, and falls back to that value when the variable is absent (local development). Each sandbox serves many requests concurrently on one process, so the app keeps in-memory counters (active requests, peak concurrency, total requests) and returns them in every JSON response. Sending parallel requests makes the concurrency model visible: the counters grow per sandbox, and a second sandbox starts from zero. On \u003Ccode>SIGTERM\u003C\u002Fcode> the server closes gracefully.","A single \u003Ccode>AWS::Serverless::WebFunction\u003C\u002Fcode> resource in the SAM template expands into three CloudFormation resources: \u003Ccode>AWS::Lambda::WebFunction\u003C\u002Fcode> (the function), \u003Ccode>AWS::Lambda::WebFunctionRevision\u003C\u002Fcode> (an immutable snapshot of code plus configuration, referencing a zip in a versioning-enabled S3 bucket) and \u003Ccode>AWS::Lambda::WebFunctionEndpoint\u003C\u002Fcode> (the HTTPS endpoint, routed 100% to that revision). SAM also generates the execution role with CloudWatch Logs permissions and writes logs to the log group named in \u003Ccode>LoggingConfig\u003C\u002Fcode>.","The endpoint uses \u003Ccode>AuthType\u003C\u002Fcode> \u003Ccode>ApplicationManaged\u003C\u002Fcode>, which makes it publicly reachable: the application owns authentication, input validation and rate limiting. Switch to \u003Ccode>IamAuth\u003C\u002Fcode> to accept only SigV4-signed requests. \u003Ccode>EndpointType\u003C\u002Fcode> \u003Ccode>HomeRegion\u003C\u002Fcode> creates a single regional endpoint; \u003Ccode>MultiRegion\u003C\u002Fcode> and \u003Ccode>PerRegion\u003C\u002Fcode> replicate it to other Regions.","Deploying a change means uploading a new zip under a new S3 key and deploying again: CloudFormation creates a new immutable revision only when the revision's properties change, so re-deploying with an unchanged key reports no changes. Because the endpoint uses \u003Ccode>AutoDeploymentMode\u003C\u002Fcode> \u003Ccode>LatestRevision\u003C\u002Fcode>, traffic moves to the new revision as soon as it is active; for weighted canaries between two revisions, set \u003Ccode>AutoDeploymentMode\u003C\u002Fcode> \u003Ccode>Disabled\u003C\u002Fcode> and \u003Ccode>RevisionWeights\u003C\u002Fcode> instead.","Node.js","100",{},{"icon1":35,"icon2":40,"icon3":44,"line1":48,"line2":52},{"x":36,"y":37,"service":38,"label":39},15,50,"icon-internet","Client",{"x":41,"y":37,"service":42,"label":43},45,"lambda-web-functions","AWS Lambda Web Function",{"x":45,"y":37,"service":46,"label":47},83,"cloudwatch","Amazon CloudWatch Logs",{"from":49,"to":50,"label":51},"icon1","icon2","HTTPS",{"from":50,"to":53,"label":54},"icon3","logs","lambda-web-http-server",{"bullets":57},[58,61,64],{"text":59,"link":60},"AWS Lambda documentation","https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fwelcome.html",{"text":62,"link":63},"AWS Serverless Application Model (SAM) documentation","https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fwhat-is-sam.html",{"text":65,"link":66},"Node.js http module","https:\u002F\u002Fnodejs.org\u002Fapi\u002Fhttp.html","patterns\u002Flambda-web-http-server-nodejs-sam",{"text":69},[70],"See the GitHub repo for detailed testing instructions.","7AhVlgWgQtmZP1HZaJHRpf1WSNlcIP7aXmRE3JcK_dc",[73],{"id":4,"title":5,"architectureURL":6,"cleanup":74,"contributors":76,"deploy":77,"description":15,"extension":16,"framework":17,"gitHub":79,"highlight":22,"introBox":81,"language":31,"level":32,"meta":83,"patternArch":84,"patternGroup":55,"patternGroupLabel":6,"resources":90,"stem":67,"testing":95,"videoId":6,"__hash__":71},{"text":75},[9],[11],{"text":78},[14],{"template":80},{"patternPath":20,"templateFile":21},{"headline":24,"text":82},[26,27,28,29,30],{},{"icon1":85,"icon2":86,"icon3":87,"line1":88,"line2":89},{"x":36,"y":37,"service":38,"label":39},{"x":41,"y":37,"service":42,"label":43},{"x":45,"y":37,"service":46,"label":47},{"from":49,"to":50,"label":51},{"from":50,"to":53,"label":54},{"bullets":91},[92,93,94],{"text":59,"link":60},{"text":62,"link":63},{"text":65,"link":66},{"text":96},[70],1791847087602]