Skip to main content

Crate lambda_web_adapter

Crate lambda_web_adapter 

Source
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:

  1. Starting as a Lambda extension alongside your web application
  2. Waiting for your application to become ready (via health checks)
  3. Receiving Lambda events and converting them to HTTP requests
  4. 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:

VariableDescriptionDefault
AWS_LWA_PORTPort your application listens on (falls back to PORT)8080
AWS_LWA_HOSTHost your application binds to127.0.0.1
AWS_LWA_READINESS_CHECK_PATHHealth check endpoint path/
AWS_LWA_READINESS_CHECK_PORTHealth check portSame as AWS_LWA_PORT
AWS_LWA_READINESS_CHECK_PROTOCOLProtocol for health checks (HTTP or TCP)HTTP
AWS_LWA_READINESS_CHECK_HEALTHY_STATUSStatus codes considered healthy (e.g., 200-399,404)100-499
AWS_LWA_ASYNC_INITEnable async initializationfalse
AWS_LWA_REMOVE_BASE_PATHBase path to strip from requestsNone
AWS_LWA_INVOKE_MODELambda invoke mode (buffered or response_stream)buffered
AWS_LWA_ENABLE_COMPRESSIONEnable 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 tracing and tracing-subscriber in Lambda functions.

Structs§

Adapter
The Lambda Web Adapter.
AdapterOptions
Configuration options for the Lambda Web Adapter.

Enums§

LambdaInvokeMode
Lambda function invoke mode.
Protocol
Protocol used for readiness checks.

Type Aliases§

Error
Error type that lambdas may result in