Serverless

Deploy to any serverless platform

srvx provides built-in support for serverless platforms, allowing you to deploy your applications to various serverless environments without changing your code.

AWS Lambda

srvx includes an AWS Lambda adapter that enables you to run your applications on AWS Lambda. The adapter handles all the necessary transformations between AWS Lambda's event format and standard web Request/Response objects, making it seamless to run your application in a serverless environment.

To AWS Lambda adapter, you can use the toLambdaHandler function from the AWS Lambda adapter:

import { toLambdaHandler } from "srvx/aws-lambda";

export const handler = toLambdaHandler({
  fetch(req: Request) {
    return Response.json({ hello: "world!" });
  },
});

The toLambdaHandler function accepts a ServerOptions object as its parameter (see Server Options for details). However, since this is a serverless environment, options related to the server instance like host and port are not respected and will be ignored.

You can find a complete example of AWS Lambda in the examples/aws-lambda directory, which includes configuration for the Serverless Framework and demonstrates how to set up API Gateway endpoints.