LambdaService

A service hosted on AWS Lambda.

Like all Services, this class configures itself across multiple Environments.

For more information, see the official documentation.

Example Usage

Basic Usage

1
import launchflow as lf
2
3
# This points to the `handler` function in the `app` module
4
api = lf.aws.LambdaService("my-api", handler="app.handler")

Custom Timeout and Memory Size

1
import launchflow as lf
2
3
service = lf.aws.LambdaService(
4
"my-lambda-service",
5
handler="app.handler",
6
timeout_seconds=30,
7
memory_size_mb=512
8
)

Environment Variables

1
import launchflow as lf
2
3
service = lf.aws.LambdaService(
4
"my-lambda-service",
5
handler="app.handler",
6
env={"STAGE": "prod", "LOG_LEVEL": "debug"}
7
)

Custom URL Configuration

1
import launchflow as lf
2
3
api_gateway = lf.aws.APIGateway("my-api-gateway")
4
# The functions will share the same API Gateway
5
read_api = lf.aws.LambdaService(
6
"my-read-api",
7
handler="app.list_users",
8
url=lf.aws.APIGatewayURL(api_gateway=api_gateway, route_key="GET /users")
9
)
10
write_api = lf.aws.LambdaService(
11
"my-write-api",
12
handler="app.create_user",
13
url=lf.aws.APIGatewayURL(api_gateway=api_gateway, route_key="POST /users")
14
)

initialization

Create a new Lambda Service.

Args:

  • name (str): The name of the service.
  • handler (Union[str, Callable]): The entry point for the Lambda function. If a callable is passed, it is converted to the proper handler string.
  • timeout_seconds (int): The timeout in seconds for the Lambda function. Defaults to 10 seconds.
  • memory_size_mb (int): The memory size for the Lambda function in MB. Defaults to 256 MB.
  • env (Optional[Dict[str, str]]): Optional environment variables for the Lambda function.
  • url (Union[LambdaURL, APIGatewayURL]): Optional URL configuration, defaults to a public Lambda URL.
  • runtime (Union[LambdaRuntime, PythonRuntime, DockerRuntime]): The runtime environment for the Lambda function. Defaults to Python runtime.
  • domain (Optional[str]): Optional custom domain. Currently unsupported, will raise an exception if provided.
  • build_directory (str): The directory to build the Lambda function from. Defaults to the current directory.
  • build_ignore (List[str]): A list of files or directories to ignore during the build process. Defaults to an empty list.

PythonRuntime

Python runtime options for Lambda functions.

Args:

  • runtime (LambdaRuntime): The Python runtime to use. Defaults to Python 3.11.
  • requirements_txt_path (Optional[str]): The path to the requirements.txt file to install dependencies from. Defaults to None.

LambdaURL

URL configuration for a Lambda function.

Args:

  • public (bool): Whether the Lambda function is public. Defaults to True.
  • cors (Optional[CORS]): Optional CORS configuration for the Lambda function. Defaults to None.

APIGatewayURL

URL configuration for a Lambda function hosted on API Gateway.

Args:

  • api_gateway (APIGateway): The API Gateway resource to use.
  • path (str): The path for the API Gateway route. Defaults to "/".
  • request (str): The request method for the API Gateway route. Defaults to "GET".
  • public (bool): Whether the API Gateway route is public. Defaults to True.