Improve error handling, comprehensive documentation, and API improvements#628
Merged
Conversation
- Extract extension registration logic into register_extension_internal() - Replace all unwrap() calls with proper error handling using ? operator - Use std::process::exit(1) instead of panic! for cleaner termination - Add proper error logging before exit - Handle missing Lambda-Extension-Identifier header gracefully This provides better error messages and cleaner process termination while still ensuring the extension exits immediately on registration failure.
- Replace unwrap() with expect() for URL parsing in Adapter::new() - Add validation for TCP protocol requirements at construction time - Use expect() with 'BUG:' prefix for invariants that should never fail - Prevents wasteful retry loops on configuration errors - Ensures fast failure with clear error messages on misconfiguration This ensures: - Configuration errors fail immediately at startup - No wasted CPU cycles retrying unrecoverable errors - Clear distinction between config errors and runtime errors - Runtime retries only happen for transient network conditions
- Move env::set_var call to before tokio runtime starts - Add Adapter::apply_runtime_proxy_config() to be called from main() - Refactor main() to manually build tokio runtime for proper ordering - Document safety requirements and future Rust compatibility This prevents race conditions and prepares for Rust 2024 edition where env::set_var will be marked as unsafe. The environment variable is now set before any threads are spawned, making it safe. Fixes critical blocker for GA release.
- Add .expect() calls to all Adapter::new() invocations in tests - Apply cargo fmt formatting fixes All 25 tests pass.
- Use derive macro for Default impl on LambdaEventType enum - Replace unnecessary to_owned() with reference in mock body
- Add .expect() calls to Adapter::new() in benchmark functions
Instead of removing support for non-namespaced env vars, emit deprecation warnings when they are used. This provides a migration path for users. Deprecated variables (will be removed in 2.0): - PORT -> use AWS_LWA_PORT - HOST -> use AWS_LWA_HOST - READINESS_CHECK_PORT -> use AWS_LWA_READINESS_CHECK_PORT - READINESS_CHECK_PATH -> use AWS_LWA_READINESS_CHECK_PATH - READINESS_CHECK_PROTOCOL -> use AWS_LWA_READINESS_CHECK_PROTOCOL - REMOVE_BASE_PATH -> use AWS_LWA_REMOVE_BASE_PATH - ASYNC_INIT -> use AWS_LWA_ASYNC_INIT When deprecated vars are used, a warning is logged: 'Environment variable X is deprecated and will be removed in version 2.0. Please use Y instead.' This is less disruptive than an immediate breaking change and gives users time to update their configurations.
…Y_STATUS New environment variable AWS_LWA_READINESS_CHECK_HEALTHY_STATUS allows users to specify which HTTP status codes are considered healthy for readiness checks. Format: Supports ranges and lists (e.g., '200-399', '200,201,204,301-399') Default: '100-499' (same behavior as previous min_unhealthy=500) Deprecated: AWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUS - Still works but emits a deprecation warning - Will be removed in version 2.0 This provides more flexibility for users who need fine-grained control over which status codes indicate a healthy application.
- Add module-level documentation with overview, quick start, and configuration table - Document Protocol enum with usage examples - Document LambdaInvokeMode enum with response streaming guidance - Document AdapterOptions struct with all fields and environment variable mappings - Document Adapter struct with lifecycle explanation - Add detailed documentation for all public methods - Document internal helper functions - All documentation builds successfully with cargo doc
- Use lambda_http::tracing::init_default_subscriber() for logging setup - Enable 'tracing' feature in lambda_http dependency - Supports AWS_LAMBDA_LOG_LEVEL environment variable (takes precedence) - Falls back to RUST_LOG if AWS_LAMBDA_LOG_LEVEL is not set - Supports JSON log format via AWS_LAMBDA_LOG_FORMAT=JSON - Removes manual tracing-subscriber setup in favor of Lambda-native solution
- Add new Logging section explaining Lambda's Advanced Logging Controls support - Clarify that AWS_LAMBDA_LOG_LEVEL and AWS_LAMBDA_LOG_FORMAT are reserved env vars set by Lambda - Document RUST_LOG as user-configurable fallback - Explain JSON log format for CloudWatch Logs Insights integration
Replace non-existent --filter-by-regression flag with awk-based parsing of critcmp CSV output to detect regressions > 10%.
roger-zhangg
reviewed
Feb 6, 2026
roger-zhangg
reviewed
Feb 6, 2026
📊 Benchmark ComparisonBenchmark Details
|
- TCP readiness checks (success and failure) - Protocol and LambdaInvokeMode From<&str> edge cases - Adapter::new() error path (invalid host) - apply_runtime_proxy_config env var behavior - parse_status_codes additional edge cases - Base path stripping (match, no-match, strip-to-root) - Deprecated env var fallback and namespaced override - Authorization source with missing header - Error status codes non-matching passthrough - Async init with readiness at init time - TCP readiness check end-to-end with request forwarding
Clients can now use lambda_web_adapter::tracing instead of importing lambda_http directly for tracing initialization.
AWS_LWA_PORT now falls back to PORT env var without emitting a deprecation warning, since PORT is a widely used convention across cloud platforms and frameworks. The fallback chain is: AWS_LWA_PORT -> PORT -> 8080 Readiness check port behavior is unchanged.
8cbf8c0 to
6202a1b
Compare
|
I see only 5 tests ran, should we run some of the skipped ones too? |
seshubaws
approved these changes
Feb 6, 2026
Contributor
Author
The first check runs linting check, unit tests, and integration tests. The later steps are for releasing the changes. |
roger-zhangg
approved these changes
Feb 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR significantly improves the Lambda Web Adapter's production readiness through better error handling, comprehensive API documentation, and several developer experience improvements.
Changes
Error Handling Improvements
unwrap()calls with proper error handling using?operator andexpect()with descriptive messagesregister_extension_internal()with proper error propagationstd::process::exit(1)instead ofpanic!for cleaner termination on registration failuresAdapter::new()now returnsResult<Adapter, Error>for proper error handling at construction timeThread Safety Fix
env::set_varusage in multi-threaded context by introducingAdapter::apply_runtime_proxy_config()main()to manually build tokio runtime, ensuring env vars are set before any threads spawnenv::set_varwill be markedunsafeNew Features
AWS_LWA_READINESS_CHECK_HEALTHY_STATUSenv var for flexible health check status code configuration200-399) and lists (200,201,204,301-399)100-499(maintains backward compatibility)lambda_http::tracing::init_default_subscriber()AWS_LAMBDA_LOG_LEVELandAWS_LAMBDA_LOG_FORMATenvironment variablesDeprecations
PORT→AWS_LWA_PORTHOST→AWS_LWA_HOSTREADINESS_CHECK_PORT→AWS_LWA_READINESS_CHECK_PORTREADINESS_CHECK_PATH→AWS_LWA_READINESS_CHECK_PATHREADINESS_CHECK_PROTOCOL→AWS_LWA_READINESS_CHECK_PROTOCOLREMOVE_BASE_PATH→AWS_LWA_REMOVE_BASE_PATHASYNC_INIT→AWS_LWA_ASYNC_INITAWS_LWA_READINESS_CHECK_MIN_UNHEALTHY_STATUSin favor ofAWS_LWA_READINESS_CHECK_HEALTHY_STATUSDocumentation
Protocol,LambdaInvokeMode,AdapterOptions, andAdapterstructsTesting
Adapter::new()returningResultDefault, unnecessaryto_owned())