[{"data":1,"prerenderedAt":916},["ShallowReactive",2],{"navigation":3,"-guide-aws-lambda":51,"-guide-aws-lambda-surround":911},[4],{"title":5,"path":6,"stem":7,"children":8,"icon":10},"Getting Started","/guide","1.guide/1.index",[9,11,16,21,26,31,36,41,46],{"title":5,"path":6,"stem":7,"icon":10},"ph:book-open-duotone",{"title":12,"path":13,"stem":14,"icon":15},"Fetch Handler","/guide/handler","1.guide/2.handler","i-fluent:target-24-regular",{"title":17,"path":18,"stem":19,"icon":20},"Server Instance","/guide/server","1.guide/3.server","radix-icons:component-instance",{"title":22,"path":23,"stem":24,"icon":25},"Middleware","/guide/middleware","1.guide/4.middleware","clarity:plugin-line",{"title":27,"path":28,"stem":29,"icon":30},"Server Options","/guide/options","1.guide/5.options","ri:settings-3-line",{"title":32,"path":33,"stem":34,"icon":35},"Bundler Usage","/guide/bundler","1.guide/6.bundler","clarity:bundle-line",{"title":37,"path":38,"stem":39,"icon":40},"Node.js Support","/guide/node","1.guide/7.node","akar-icons:node-fill",{"title":42,"path":43,"stem":44,"icon":45},"AWS Lambda","/guide/aws-lambda","1.guide/8.aws-lambda","clarity:cloud-traffic-line",{"title":47,"path":48,"stem":49,"icon":50},"Using CLI","/guide/cli","1.guide/9.cli","garden:terminal-cli-stroke-12",{"id":52,"title":42,"body":53,"description":905,"extension":906,"meta":907,"navigation":908,"path":43,"seo":909,"stem":44,"__hash__":910},"content/1.guide/8.aws-lambda.md",{"type":54,"value":55,"toc":900,"icon":45},"minimark",[56,60,72,222,244,254,259,265,278,281,302,306,312,465,468,489,493,502,512,882,896],[57,58,59],"p",{},"srvx provides an AWS Lambda compatibility adapter that handles all the necessary transformations between AWS Lambda's event format and standard web Request/Response objects.",[57,61,62,63,67,68,71],{},"To use the AWS Lambda adapter, import the ",[64,65,66],"code",{},"toLambdaHandler"," function from ",[64,69,70],{},"\"srvx/aws-lambda\"",":",[73,74,80],"pre",{"className":75,"code":76,"filename":77,"language":78,"meta":79,"style":79},"language-ts shiki shiki-themes github-light github-dark github-dark","import { toLambdaHandler } from \"srvx/aws-lambda\";\nimport { serveStatic } from \"srvx/static\";\n\nexport const handler = toLambdaHandler({\n  middleware: [serveStatic({ dir: \"public\" })],\n  fetch(req: Request) {\n    return Response.json({ hello: \"world!\" });\n  },\n});\n","server.ts","ts","",[64,81,82,105,120,127,150,168,189,210,216],{"__ignoreMap":79},[83,84,87,91,95,98,102],"span",{"class":85,"line":86},"line",1,[83,88,90],{"class":89},"so5gQ","import",[83,92,94],{"class":93},"slsVL"," { toLambdaHandler } ",[83,96,97],{"class":89},"from",[83,99,101],{"class":100},"sfrk1"," \"srvx/aws-lambda\"",[83,103,104],{"class":93},";\n",[83,106,108,110,113,115,118],{"class":85,"line":107},2,[83,109,90],{"class":89},[83,111,112],{"class":93}," { serveStatic } ",[83,114,97],{"class":89},[83,116,117],{"class":100}," \"srvx/static\"",[83,119,104],{"class":93},[83,121,123],{"class":85,"line":122},3,[83,124,126],{"emptyLinePlaceholder":125},true,"\n",[83,128,130,133,136,140,143,147],{"class":85,"line":129},4,[83,131,132],{"class":89},"export",[83,134,135],{"class":89}," const",[83,137,139],{"class":138},"suiK_"," handler",[83,141,142],{"class":89}," =",[83,144,146],{"class":145},"shcOC"," toLambdaHandler",[83,148,149],{"class":93},"({\n",[83,151,153,156,159,162,165],{"class":85,"line":152},5,[83,154,155],{"class":93},"  middleware: [",[83,157,158],{"class":145},"serveStatic",[83,160,161],{"class":93},"({ dir: ",[83,163,164],{"class":100},"\"public\"",[83,166,167],{"class":93}," })],\n",[83,169,171,174,177,181,183,186],{"class":85,"line":170},6,[83,172,173],{"class":145},"  fetch",[83,175,176],{"class":93},"(",[83,178,180],{"class":179},"sQHwn","req",[83,182,71],{"class":89},[83,184,185],{"class":145}," Request",[83,187,188],{"class":93},") {\n",[83,190,192,195,198,201,204,207],{"class":85,"line":191},7,[83,193,194],{"class":89},"    return",[83,196,197],{"class":93}," Response.",[83,199,200],{"class":145},"json",[83,202,203],{"class":93},"({ hello: ",[83,205,206],{"class":100},"\"world!\"",[83,208,209],{"class":93}," });\n",[83,211,213],{"class":85,"line":212},8,[83,214,215],{"class":93},"  },\n",[83,217,219],{"class":85,"line":218},9,[83,220,221],{"class":93},"});\n",[57,223,224,225,227,228,231,232,235,236,239,240,243],{},"The ",[64,226,66],{}," function accepts a ",[64,229,230],{},"ServerOptions"," object as its parameter (see ",[233,234,27],"a",{"href":28}," for details). However, since this is a serverless environment, options related to the server instance like ",[64,237,238],{},"host"," and ",[64,241,242],{},"port"," are not respected and will be ignored.",[57,245,246,247,253],{},"You can find a complete example of AWS Lambda in the ",[233,248,252],{"href":249,"rel":250},"https://github.com/h3js/srvx/tree/main/examples/aws-lambda",[251],"nofollow","examples/aws-lambda"," directory.",[255,256,258],"h2",{"id":257},"serving-static-assets","Serving Static Assets",[57,260,261,262,264],{},"The example above uses ",[64,263,158],{}," middleware to serve static files directly from the Lambda function. While this works for simple use cases, it comes with limitations:",[266,267,268,272,275],"ul",{},[269,270,271],"li",{},"Lambda has a deployment package size limit (50MB zipped, 250MB unzipped)",[269,273,274],{},"Each static file request incurs Lambda invocation costs",[269,276,277],{},"Cold starts affect static file delivery latency",[57,279,280],{},"For production applications, consider these alternatives:",[266,282,283,290,296],{},[269,284,285,289],{},[286,287,288],"strong",{},"Amazon S3 + CloudFront",": Store static assets in S3 and serve them through CloudFront CDN for better performance and lower costs",[269,291,292,295],{},[286,293,294],{},"API Gateway Binary Support",": Configure API Gateway to serve static files directly from S3 without invoking Lambda",[269,297,298,301],{},[286,299,300],{},"Separate Static Hosting",": Use dedicated static hosting services (Vercel, Netlify, or S3 static website hosting) for your assets",[255,303,305],{"id":304},"invoking-lambda-handlers","Invoking Lambda Handlers",[57,307,224,308,311],{},[64,309,310],{},"invokeLambdaHandler"," utility allows you to invoke an AWS Lambda handler using standard Web Request/Response objects. This is useful for testing your Lambda handlers locally or integrating them into other web-based workflows.",[73,313,315],{"className":75,"code":314,"language":78,"meta":79,"style":79},"import { toLambdaHandler, invokeLambdaHandler } from \"srvx/aws-lambda\";\n\nconst handler = toLambdaHandler({\n  fetch(req: Request) {\n    return Response.json({ hello: \"world!\" });\n  },\n});\n\n// Invoke the handler with a standard Request\nconst request = new Request(\"https://example.com/api\");\nconst response = await invokeLambdaHandler(handler, request);\n\nconsole.log(await response.json()); // { hello: \"world!\" }\n",[64,316,317,330,334,347,361,375,379,383,387,393,416,435,440],{"__ignoreMap":79},[83,318,319,321,324,326,328],{"class":85,"line":86},[83,320,90],{"class":89},[83,322,323],{"class":93}," { toLambdaHandler, invokeLambdaHandler } ",[83,325,97],{"class":89},[83,327,101],{"class":100},[83,329,104],{"class":93},[83,331,332],{"class":85,"line":107},[83,333,126],{"emptyLinePlaceholder":125},[83,335,336,339,341,343,345],{"class":85,"line":122},[83,337,338],{"class":89},"const",[83,340,139],{"class":138},[83,342,142],{"class":89},[83,344,146],{"class":145},[83,346,149],{"class":93},[83,348,349,351,353,355,357,359],{"class":85,"line":129},[83,350,173],{"class":145},[83,352,176],{"class":93},[83,354,180],{"class":179},[83,356,71],{"class":89},[83,358,185],{"class":145},[83,360,188],{"class":93},[83,362,363,365,367,369,371,373],{"class":85,"line":152},[83,364,194],{"class":89},[83,366,197],{"class":93},[83,368,200],{"class":145},[83,370,203],{"class":93},[83,372,206],{"class":100},[83,374,209],{"class":93},[83,376,377],{"class":85,"line":170},[83,378,215],{"class":93},[83,380,381],{"class":85,"line":191},[83,382,221],{"class":93},[83,384,385],{"class":85,"line":212},[83,386,126],{"emptyLinePlaceholder":125},[83,388,389],{"class":85,"line":218},[83,390,392],{"class":391},"sCsY4","// Invoke the handler with a standard Request\n",[83,394,396,398,401,403,406,408,410,413],{"class":85,"line":395},10,[83,397,338],{"class":89},[83,399,400],{"class":138}," request",[83,402,142],{"class":89},[83,404,405],{"class":89}," new",[83,407,185],{"class":145},[83,409,176],{"class":93},[83,411,412],{"class":100},"\"https://example.com/api\"",[83,414,415],{"class":93},");\n",[83,417,419,421,424,426,429,432],{"class":85,"line":418},11,[83,420,338],{"class":89},[83,422,423],{"class":138}," response",[83,425,142],{"class":89},[83,427,428],{"class":89}," await",[83,430,431],{"class":145}," invokeLambdaHandler",[83,433,434],{"class":93},"(handler, request);\n",[83,436,438],{"class":85,"line":437},12,[83,439,126],{"emptyLinePlaceholder":125},[83,441,443,446,449,451,454,457,459,462],{"class":85,"line":442},13,[83,444,445],{"class":93},"console.",[83,447,448],{"class":145},"log",[83,450,176],{"class":93},[83,452,453],{"class":89},"await",[83,455,456],{"class":93}," response.",[83,458,200],{"class":145},[83,460,461],{"class":93},"()); ",[83,463,464],{"class":391},"// { hello: \"world!\" }\n",[57,466,467],{},"The function handles all conversions internally:",[469,470,472,480,483],"steps",{"level":471},"4",[473,474,475,476,479],"h4",{},"Converts the Web ",[64,477,478],{},"Request"," to an AWS Lambda event (compatible with both v1 and v2 API Gateway formats)",[473,481,482],{},"Invokes the Lambda handler with a mock context",[473,484,485,486],{},"Converts the AWS Lambda result back to a standard Web ",[64,487,488],{},"Response",[255,490,492],{"id":491},"response-streaming","Response Streaming",[57,494,495,496,501],{},"AWS Lambda supports ",[233,497,500],{"href":498,"rel":499},"https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html",[251],"response streaming"," which allows you to send response data progressively as it becomes available. This improves Time To First Byte (TTFB) and enables streaming large responses (up to 20MB vs 6MB buffered limit).",[57,503,504,505,508,509,71],{},"To use response streaming, wrap your handler with ",[64,506,507],{},"awslambda.streamifyResponse()"," and use ",[64,510,511],{},"handleLambdaEventWithStream",[73,513,515],{"className":75,"code":514,"language":78,"meta":79,"style":79},"import { handleLambdaEventWithStream, type AWSLambdaStreamingHandler } from \"srvx/aws-lambda\";\n\nconst fetchHandler = async (request: Request) => {\n  // Create a streaming response\n  const stream = new ReadableStream({\n    async start(controller) {\n      controller.enqueue(new TextEncoder().encode(\"Hello, \"));\n      await new Promise((r) => setTimeout(r, 100));\n      controller.enqueue(new TextEncoder().encode(\"streaming \"));\n      await new Promise((r) => setTimeout(r, 100));\n      controller.enqueue(new TextEncoder().encode(\"world!\"));\n      controller.close();\n    },\n  });\n\n  return new Response(stream, {\n    headers: { \"Content-Type\": \"text/plain\" },\n  });\n};\n\n// Export a streaming handler\nexport const handler: AWSLambdaStreamingHandler = awslambda.streamifyResponse(\n  (event, responseStream, context) =>\n    handleLambdaEventWithStream(fetchHandler, event, responseStream, context),\n);\n",[64,516,517,536,540,571,576,593,608,638,669,692,716,738,748,753,759,764,778,796,801,807,812,818,843,868,877],{"__ignoreMap":79},[83,518,519,521,524,527,530,532,534],{"class":85,"line":86},[83,520,90],{"class":89},[83,522,523],{"class":93}," { handleLambdaEventWithStream, ",[83,525,526],{"class":89},"type",[83,528,529],{"class":93}," AWSLambdaStreamingHandler } ",[83,531,97],{"class":89},[83,533,101],{"class":100},[83,535,104],{"class":93},[83,537,538],{"class":85,"line":107},[83,539,126],{"emptyLinePlaceholder":125},[83,541,542,544,547,549,552,555,558,560,562,565,568],{"class":85,"line":122},[83,543,338],{"class":89},[83,545,546],{"class":145}," fetchHandler",[83,548,142],{"class":89},[83,550,551],{"class":89}," async",[83,553,554],{"class":93}," (",[83,556,557],{"class":179},"request",[83,559,71],{"class":89},[83,561,185],{"class":145},[83,563,564],{"class":93},") ",[83,566,567],{"class":89},"=>",[83,569,570],{"class":93}," {\n",[83,572,573],{"class":85,"line":129},[83,574,575],{"class":391},"  // Create a streaming response\n",[83,577,578,581,584,586,588,591],{"class":85,"line":152},[83,579,580],{"class":89},"  const",[83,582,583],{"class":138}," stream",[83,585,142],{"class":89},[83,587,405],{"class":89},[83,589,590],{"class":145}," ReadableStream",[83,592,149],{"class":93},[83,594,595,598,601,603,606],{"class":85,"line":170},[83,596,597],{"class":89},"    async",[83,599,600],{"class":145}," start",[83,602,176],{"class":93},[83,604,605],{"class":179},"controller",[83,607,188],{"class":93},[83,609,610,613,616,618,621,624,627,630,632,635],{"class":85,"line":191},[83,611,612],{"class":93},"      controller.",[83,614,615],{"class":145},"enqueue",[83,617,176],{"class":93},[83,619,620],{"class":89},"new",[83,622,623],{"class":145}," TextEncoder",[83,625,626],{"class":93},"().",[83,628,629],{"class":145},"encode",[83,631,176],{"class":93},[83,633,634],{"class":100},"\"Hello, \"",[83,636,637],{"class":93},"));\n",[83,639,640,643,645,648,651,654,656,658,661,664,667],{"class":85,"line":212},[83,641,642],{"class":89},"      await",[83,644,405],{"class":89},[83,646,647],{"class":138}," Promise",[83,649,650],{"class":93},"((",[83,652,653],{"class":179},"r",[83,655,564],{"class":93},[83,657,567],{"class":89},[83,659,660],{"class":145}," setTimeout",[83,662,663],{"class":93},"(r, ",[83,665,666],{"class":138},"100",[83,668,637],{"class":93},[83,670,671,673,675,677,679,681,683,685,687,690],{"class":85,"line":218},[83,672,612],{"class":93},[83,674,615],{"class":145},[83,676,176],{"class":93},[83,678,620],{"class":89},[83,680,623],{"class":145},[83,682,626],{"class":93},[83,684,629],{"class":145},[83,686,176],{"class":93},[83,688,689],{"class":100},"\"streaming \"",[83,691,637],{"class":93},[83,693,694,696,698,700,702,704,706,708,710,712,714],{"class":85,"line":395},[83,695,642],{"class":89},[83,697,405],{"class":89},[83,699,647],{"class":138},[83,701,650],{"class":93},[83,703,653],{"class":179},[83,705,564],{"class":93},[83,707,567],{"class":89},[83,709,660],{"class":145},[83,711,663],{"class":93},[83,713,666],{"class":138},[83,715,637],{"class":93},[83,717,718,720,722,724,726,728,730,732,734,736],{"class":85,"line":418},[83,719,612],{"class":93},[83,721,615],{"class":145},[83,723,176],{"class":93},[83,725,620],{"class":89},[83,727,623],{"class":145},[83,729,626],{"class":93},[83,731,629],{"class":145},[83,733,176],{"class":93},[83,735,206],{"class":100},[83,737,637],{"class":93},[83,739,740,742,745],{"class":85,"line":437},[83,741,612],{"class":93},[83,743,744],{"class":145},"close",[83,746,747],{"class":93},"();\n",[83,749,750],{"class":85,"line":442},[83,751,752],{"class":93},"    },\n",[83,754,756],{"class":85,"line":755},14,[83,757,758],{"class":93},"  });\n",[83,760,762],{"class":85,"line":761},15,[83,763,126],{"emptyLinePlaceholder":125},[83,765,767,770,772,775],{"class":85,"line":766},16,[83,768,769],{"class":89},"  return",[83,771,405],{"class":89},[83,773,774],{"class":145}," Response",[83,776,777],{"class":93},"(stream, {\n",[83,779,781,784,787,790,793],{"class":85,"line":780},17,[83,782,783],{"class":93},"    headers: { ",[83,785,786],{"class":100},"\"Content-Type\"",[83,788,789],{"class":93},": ",[83,791,792],{"class":100},"\"text/plain\"",[83,794,795],{"class":93}," },\n",[83,797,799],{"class":85,"line":798},18,[83,800,758],{"class":93},[83,802,804],{"class":85,"line":803},19,[83,805,806],{"class":93},"};\n",[83,808,810],{"class":85,"line":809},20,[83,811,126],{"emptyLinePlaceholder":125},[83,813,815],{"class":85,"line":814},21,[83,816,817],{"class":391},"// Export a streaming handler\n",[83,819,821,823,825,827,829,832,834,837,840],{"class":85,"line":820},22,[83,822,132],{"class":89},[83,824,135],{"class":89},[83,826,139],{"class":138},[83,828,71],{"class":89},[83,830,831],{"class":145}," AWSLambdaStreamingHandler",[83,833,142],{"class":89},[83,835,836],{"class":93}," awslambda.",[83,838,839],{"class":145},"streamifyResponse",[83,841,842],{"class":93},"(\n",[83,844,846,849,852,855,858,860,863,865],{"class":85,"line":845},23,[83,847,848],{"class":93},"  (",[83,850,851],{"class":179},"event",[83,853,854],{"class":93},", ",[83,856,857],{"class":179},"responseStream",[83,859,854],{"class":93},[83,861,862],{"class":179},"context",[83,864,564],{"class":93},[83,866,867],{"class":89},"=>\n",[83,869,871,874],{"class":85,"line":870},24,[83,872,873],{"class":145},"    handleLambdaEventWithStream",[83,875,876],{"class":93},"(fetchHandler, event, responseStream, context),\n",[83,878,880],{"class":85,"line":879},25,[83,881,415],{"class":93},[883,884,885],"note",{},[57,886,887,888,891,892,895],{},"\nResponse streaming requires a Lambda Function URL with ",[64,889,890],{},"--invoke-mode RESPONSE_STREAM"," or the ",[64,893,894],{},"InvokeWithResponseStream"," API. It does not work with API Gateway or Application Load Balancer for progressive streaming.",[897,898,899],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":79,"searchDepth":107,"depth":107,"links":901},[902,903,904],{"id":257,"depth":107,"text":258},{"id":304,"depth":107,"text":305},{"id":491,"depth":107,"text":492},"AWS Lambda compatibility","md",{"automd":125,"icon":45},{"icon":45},{"title":42,"description":905},"gl2hNGMIJYF80XhWqEaUKhz4Q4D4VWeU8eY0rvr5B9Y",[912,914],{"title":37,"path":38,"stem":39,"description":913,"icon":40,"children":-1},"Learn more about Node.js compatibility with srvx.",{"title":47,"path":48,"stem":49,"description":915,"icon":50,"children":-1},"Use the srvx CLI command to easily start a development or production server.",1771317514430]