This document provides an overview of per-lambda configuration in OpenLambda, detailing trigger types, configuration options, and usage.
Each lambda function in OpenLambda can optionally be configured using an ol.yaml file located in the function's directory. This configuration file defines how the function is triggered and any specific execution parameters.
A typical ol.yaml file follows this structure:
triggers:
http:
- method: PUT
- method: PATCH
kafka:
- bootstrap_servers:
- "localhost:9092"
topics:
- "my-topic"
environment:
MY_ENV_VAR1: "value1"
MY_ENV_VAR2: "value2"OpenLambda currently supports HTTP and Kafka triggers.
Defines which HTTP methods can be used to invoke the lambda.
Example:
triggers:
http:
- method: GET
- method: POSTIn this case, the lambda accepts GET and POST requests.
Defines Kafka topics the lambda should consume from. When a message arrives on a configured topic, the lambda is invoked with the message as the request body.
Example:
triggers:
kafka:
- bootstrap_servers:
- "localhost:9092"
topics:
- "my-topic"
auto_offset_reset: "latest"| Field | Type | Required | Description |
|---|---|---|---|
bootstrap_servers |
[]string |
Yes | List of Kafka broker addresses. |
topics |
[]string |
Yes | Topics this lambda should consume from. |
auto_offset_reset |
string |
No | Where to start reading if no committed offset exists. "latest" (default) or "earliest". |
A lambda can define multiple Kafka trigger entries. Each entry creates a separate consumer. For more details on Kafka triggers, including how to access Kafka metadata headers in your handler, see kafka-triggers.md.
Defines environment variables that will be available to the lambda function at runtime.
Example:
environment:
MY_ENV_VAR1: "production"
MY_ENV_VAR2: "enabled"These variables can be accessed in your lambda code using standard environment variable methods (e.g., os.environ in Python).
Note: Environment variables defined in ol.yaml are written to a .env file in the lambda's directory during execution. If your lambda already has a .env file, it will be overwritten with the values from ol.yaml.
By default, OpenLambda expects Python lambda functions to be defined in a file named f.py. You can override this by setting the OL_ENTRY_FILE environment variable to specify a different entry file.
Example:
environment:
OL_ENTRY_FILE: "app.py"With this configuration:
- OpenLambda will look for
app.pyinstead off.pywhen detecting the Python runtime - The Python runtime will import the
appmodule instead off - For standard functions, define your handler as
def f(event)in the specified file - For Flask/WSGI applications, define your
appobject in the specified file
This is useful when you want to use conventional naming (e.g., app.py for Flask applications) or integrate existing code without renaming files.
By default, OpenLambda reuses the same sandbox across multiple invocations of a lambda function to improve performance. In some cases, such as when strict isolation is required or when avoiding state persistence between invocations, it may be desirable to create a fresh sandbox for each invocation.
This behavior can be controlled using the reuse-sandbox option.
Example:
reuse-sandbox: falseWith this configuration:
- A new sandbox is created for each lambda invocation
- The sandbox is destroyed after the invocation completes
If reuse-sandbox is not specified, OpenLambda defaults to reusing sandboxes across invocations.
Create an ol.yaml file inside the lambda function directory with the desired configuration.
Ensure the OpenLambda framework is set up and execute your lambda as per the defined triggers.
- HTTP triggers must specify valid HTTP methods (GET, POST, PUT, DELETE, etc.).
- If no triggers are specified or no configuration file exists in the lambda function directory, OpenLambda will apply default behavior allowing all HTTP methods.