Expand description
§Lambda Web Adapter
Lambda Web Adapter allows you to run web applications on AWS Lambda without code changes. It acts as a bridge between the Lambda Runtime API and your web application, translating Lambda events into HTTP requests and forwarding them to your application.
§Overview
The adapter works by:
- Starting as a Lambda extension alongside your web application
- Waiting for your application to become ready (via health checks)
- Receiving Lambda events and converting them to HTTP requests
- Forwarding requests to your application and returning responses to Lambda
§Quick Start
use lambda_web_adapter::{Adapter, AdapterOptions, Error};
fn main() -> Result<(), Error> {
// Apply proxy config before starting tokio runtime
Adapter::apply_runtime_proxy_config();
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
runtime.block_on(async {
let options = AdapterOptions::default();
let mut adapter = Adapter::new(&options)?;
adapter.register_default_extension();
adapter.check_init_health().await;
adapter.run().await
})
}§Configuration
The adapter is configured via environment variables. All variables use the AWS_LWA_ prefix:
| Variable | Description | Default |
|---|---|---|
AWS_LWA_PORT | Port your application listens on (falls back to PORT) | 8080 |
AWS_LWA_HOST | Host your application binds to | 127.0.0.1 |
AWS_LWA_READINESS_CHECK_PATH | Health check endpoint path | / |
AWS_LWA_READINESS_CHECK_PORT | Health check port | Same as AWS_LWA_PORT |
AWS_LWA_READINESS_CHECK_PROTOCOL | Protocol for health checks (HTTP or TCP) | HTTP |
AWS_LWA_READINESS_CHECK_HEALTHY_STATUS | Status codes considered healthy (e.g., 200-399,404) | 100-499 |
AWS_LWA_ASYNC_INIT | Enable async initialization | false |
AWS_LWA_REMOVE_BASE_PATH | Base path to strip from requests | None |
AWS_LWA_INVOKE_MODE | Lambda invoke mode (buffered or response_stream) | buffered |
AWS_LWA_ENABLE_COMPRESSION | Enable response compression (buffered mode only) | false |
§Response Streaming
For applications that need to stream responses (e.g., Server-Sent Events, large file downloads),
set AWS_LWA_INVOKE_MODE=response_stream. This requires configuring your Lambda function URL
with InvokeMode: RESPONSE_STREAM.
Modules§
- tracing
- This module provides primitives to work with
tracingandtracing-subscriberin Lambda functions.
Structs§
- Adapter
- The Lambda Web Adapter.
- Adapter
Options - Configuration options for the Lambda Web Adapter.
Enums§
- Lambda
Invoke Mode - Lambda function invoke mode.
- Protocol
- Protocol used for readiness checks.
Type Aliases§
- Error
- Error type that lambdas may result in