| title | AWS Lambda Backend |
|---|---|
| sidebar_position | 13 |
The gateway can invoke AWS Lambda functions as backends, translating HTTP requests into Lambda invocations and returning the function response to the client.
When Lambda is enabled on a route, the Lambda handler replaces the standard HTTP reverse proxy as the innermost handler. Incoming HTTP requests are converted to an API Gateway-style JSON payload and sent to the configured Lambda function via the AWS SDK.
routes:
- id: serverless-api
path: /api/compute
path_prefix: true
lambda:
enabled: true
function_name: my-api-handler
region: us-west-2
max_retries: 2| Field | Type | Default | Description |
|---|---|---|---|
enabled |
bool | false |
Enable Lambda backend for this route |
function_name |
string | required | AWS Lambda function name or ARN |
region |
string | us-east-1 |
AWS region for the Lambda function |
max_retries |
int | 0 |
Maximum retry attempts for failed invocations |
The handler converts HTTP requests into a JSON payload matching the API Gateway proxy integration format:
GET requests:
{
"httpMethod": "GET",
"path": "/api/compute/data",
"queryParameters": {"key": ["value"]},
"headers": {"Content-Type": "application/json"},
"pathParameters": {}
}POST/PUT/DELETE requests:
{
"httpMethod": "POST",
"path": "/api/compute/data",
"headers": {"Content-Type": "application/json"},
"body": "{\"name\": \"example\"}",
"pathParameters": {}
}- Successful invocations return 200 with the Lambda function's payload as
application/json. - Function errors (non-null
FunctionError) return 502 with the error payload. - SDK errors (network failures, permissions) return 502 with an error message.
The handler uses the default AWS SDK credential chain (aws-sdk-go-v2/config.LoadDefaultConfig). Credentials are resolved from (in order):
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY) - Shared credentials file (
~/.aws/credentials) - IAM instance profile / ECS task role / IRSA (Kubernetes)
Lambda replaces the proxy as the innermost handler. It is mutually exclusive with:
backends,service,upstream(standard proxy targets)echo,static,fastcgi,sequential,aggregateamqp,pubsub
All upstream middleware (auth, rate limiting, WAF, etc.) still applies to Lambda routes.
GET /lambda
Returns per-route Lambda stats:
{
"serverless-api": {
"function_name": "my-api-handler",
"total_requests": 5000,
"total_errors": 12,
"total_invokes": 5000
}
}function_nameis required when enabled- Lambda is mutually exclusive with other innermost handlers (backends, static, echo, fastcgi, sequential, aggregate, amqp, pubsub)