You can configure your Lambda function URLs to stream response payloads back to clients. Response streaming can benefit latency sensitive applications by improving time to first byte (TTFB) performance. This is because you can send partial responses back to the client as they become available. Additionally, you can use response streaming to build functions that return larger payloads. Response stream payloads have a soft limit of 20 MB as compared to the 6 MB limit for buffered responses. Streaming a response also means that your function doesnât need to fit the entire response in memory. For very large responses, this can reduce the amount of memory you need to configure for your function.
The speed at which Lambda streams your responses depends on the response size. The streaming rate for the first 6MB of your functionâs response is uncapped. For responses larger than 6MB, the remainder of the response is subject to a bandwidth cap. For more information on streaming bandwidth, see Bandwidth limits for response streaming.
Streaming responses incurs a cost. For more information, see AWS Lambda Pricing.
Lambda supports response streaming on Node.js managed runtimes. For other languages, you can use a custom runtime with a custom Runtime API integration to stream responses or use the Lambda Web Adapter. You can stream responses through Lambda function URLs, the AWS SDK, or using the Lambda InvokeWithResponseStream API.
NoteWhen testing your function through the Lambda console, you'll always see responses as buffered.
Bandwidth limits for response streamingThe first 6MB of your functionâs response payload has uncapped bandwidth. After this initial burst, Lambda streams your response at a maximum rate of 2MBps. If your function responses never exceed 6MB, then this bandwidth limit never applies.
NoteBandwidth limits only apply to your functionâs response payload, and not to network access by your function.
The rate of uncapped bandwidth varies depending on a number of factors, including your functionâs processing speed. You can normally expect a rate higher than 2MBps for the first 6MB of your functionâs response. If your function is streaming a response to a destination outside of AWS, the streaming rate also depends on the speed of the external internet connection.
VPC compatibility with response streamingWhen using Lambda functions in a VPC environment, there are important considerations for response streaming:
Lambda function URLs do not support response streaming within a VPC environment.
You can use response streaming within a VPC by invoking your Lambda function through the AWS SDK using the InvokeWithResponseStream
API. This requires setting up the appropriate VPC endpoints for Lambda.
For VPC environments, you'll need to create an interface VPC endpoint for Lambda to enable communication between your resources in the VPC and the Lambda service.
A typical architecture for response streaming in a VPC might include:
Client in VPC -> Interface VPC endpoint for Lambda -> Lambda function -> Response streaming back through the same path
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4