You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: support Lambda Managed Instance
* fix example and tests
* chore: update dependencies
* chore: fix formatting
* docs: fix LMI example README to match SAM template
* test: add concurrent request forwarding and body isolation tests
* test: add concurrent request forwarding tests for LMI support
| AWS_LWA_READINESS_CHECK_PROTOCOL | readiness check protocol: "http" or "tcp", default is "http" | "http" |
102
102
| AWS_LWA_READINESS_CHECK_HEALTHY_STATUS | HTTP status codes considered healthy (e.g., "200-399" or "200,201,204,301-399") | "100-499" |
103
103
| AWS_LWA_ASYNC_INIT | enable asynchronous initialization for long initialization functions | "false" |
104
104
| AWS_LWA_REMOVE_BASE_PATH | the base path to be removed from request path | None |
105
-
| AWS_LWA_ENABLE_COMPRESSION | enable gzip compression for response body | "false" |
105
+
| AWS_LWA_ENABLE_COMPRESSION | enable gzip/br compression for response body (buffered mode only)| "false" |
106
106
| AWS_LWA_INVOKE_MODE | Lambda function invoke mode: "buffered" or "response_stream", default is "buffered" | "buffered" |
107
107
| AWS_LWA_PASS_THROUGH_PATH | the path for receiving event payloads that are passed through from non-http triggers | "/events" |
108
108
| AWS_LWA_AUTHORIZATION_SOURCE | a header name to be replaced to `Authorization`| None |
@@ -131,8 +131,8 @@ For example, you could have configured your API Gateway to have a /orders/{proxy
131
131
Each resource is handled by a separate Lambda functions. For this reason, the application inside Lambda may not be aware of the fact that the /orders path exists.
132
132
Use AWS_LWA_REMOVE_BASE_PATH to remove the /orders prefix when routing requests to the application. Defaults to empty string. Checkout [SpringBoot](examples/springboot) example.
133
133
134
-
**AWS_LWA_ENABLE_COMPRESSION** - Lambda Web Adapter supports gzip compression for response body. This feature is disabled by default. Enable it by setting environment variable `AWS_LWA_ENABLE_COMPRESSION` to `true`.
135
-
When enabled, this will compress responses unless it's an image as determined by the content-type starting with `image` or the response is less than 32 bytes. This will also compress HTTP/1.1 chunked streaming response.
134
+
**AWS_LWA_ENABLE_COMPRESSION** - Lambda Web Adapter supports gzip/br compression for response body. This feature is disabled by default. Enable it by setting environment variable `AWS_LWA_ENABLE_COMPRESSION` to `true`.
135
+
When enabled, this will compress responses unless it's an image as determined by the content-type starting with `image` or the response is less than 32 bytes. Compression is not supported with response streaming (`AWS_LWA_INVOKE_MODE=response_stream`). If both are enabled, compression will be automatically disabled with a warning.
136
136
137
137
**AWS_LWA_INVOKE_MODE** - Lambda function invoke mode, this should match Function Url invoke mode. The default is "buffered". When configured as "response_stream", Lambda Web Adapter will stream response to Lambda service [blog](https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/).
138
138
Please check out [FastAPI with Response Streaming](examples/fastapi-response-streaming) example.
@@ -172,6 +172,23 @@ Lambda Web Adapter forwards this information to the web application in a Http He
172
172
173
173
Lambda Web Adapter forwards this information to the web application in a Http Header named "x-amzn-lambda-context". In the web application, you can retrieve the value of this http header and deserialize it into a JSON object. Check out [Express.js in Zip](examples/expressjs-zip) on how to use it.
174
174
175
+
## Lambda Managed Instances
176
+
177
+
Lambda Web Adapter supports [Lambda Managed Instances](https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances.html), which allows a single Lambda execution environment to handle multiple concurrent requests. This can improve throughput and reduce costs for I/O-bound workloads.
178
+
179
+
When running on Lambda Managed Instances, Lambda Web Adapter automatically handles concurrent invocations by forwarding multiple requests to your web application simultaneously. Since most web frameworks (Express.js, FastAPI, Spring Boot, etc.) are already designed to handle concurrent requests, your application should work without modification.
180
+
181
+
### Considerations for Multi-Concurrency
182
+
183
+
When using Lambda Managed Instances, keep these points in mind:
184
+
185
+
-**Shared state**: Global variables and in-memory caches are shared across concurrent requests. Ensure your application handles shared state safely.
186
+
-**Connection pooling**: Use connection pools for databases and external services rather than single connections.
187
+
-**File system**: The `/tmp` directory is shared across concurrent requests. Use unique file names or implement file locking to avoid conflicts.
188
+
-**Resource limits**: Memory and CPU are shared across concurrent requests. Monitor resource usage under concurrent load.
189
+
190
+
Lambda Managed Instances works with both buffered and response streaming modes.
191
+
175
192
## Graceful Shutdown
176
193
177
194
For a function with Lambda Extensions registered, Lambda enables shutdown phase for the function. When Lambda service is about to shut down a Lambda execution environment,
@@ -203,6 +220,7 @@ The `AWS_LWA_LAMBDA_RUNTIME_API_PROXY` environment varible makes the Lambda Web
203
220
-[FastAPI with Background Tasks](examples/fastapi-background-tasks)
204
221
-[FastAPI with Response Streaming](examples/fastapi-response-streaming)
205
222
-[FastAPI with Response Streaming in Zip](examples/fastapi-response-streaming-zip)
223
+
-[FastAPI with Response Streaming on Lambda Managed Instances](examples/fastapi-response-streaming-lmi)
206
224
-[FastAPI Response Streaming Backend with IAM Auth](examples/fastapi-backend-only-response-streaming/)
# FastAPI Response Streaming with Lambda Managed Instances
2
+
3
+
This example shows how to use Lambda Web Adapter to run a FastAPI application with response streaming on [Lambda Managed Instances](https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances.html) (LMI).
4
+
5
+
Lambda Managed Instances allows a single Lambda execution environment to handle multiple concurrent requests, improving throughput and reducing costs for I/O-bound workloads like streaming responses.
6
+
7
+
## Prerequisites
8
+
9
+
Lambda Managed Instances requires a VPC with:
10
+
- At least one subnet (two subnets recommended)
11
+
- A security group that allows outbound traffic
12
+
13
+
If you don't have a VPC configured, you can use the default VPC or create one.
14
+
15
+
## How does it work?
16
+
17
+
This example combines three Lambda features:
18
+
19
+
1.**Lambda Web Adapter** - Runs your FastAPI app on Lambda without code changes
20
+
2.**Response Streaming** - Streams responses back to clients as they're generated
- `SubnetIds`- Comma-separated list of subnet IDs (e.g., `subnet-abc123,subnet-def456`)
88
+
- `SecurityGroupIds`- Comma-separated list of security group IDs (e.g., `sg-abc123`)
89
+
90
+
## Verify it works
91
+
92
+
Open the Function URL in a browser. You should see a message stream back character by character, with a unique request ID prefix like `[a1b2c3d4] This is streaming from Lambda Managed Instances!`.
93
+
94
+
### Test concurrent requests
95
+
96
+
To verify LMI is working, send multiple concurrent requests:
0 commit comments