Response streaming for Lambda functions
Lambda functions can natively stream response payloads back to clients through Lambda function URLs or by using the InvokeWithResponseStream
Note
Lambda response streaming is not yet available in all Amazon Web Services Regions. Please refer to Builder Center's Amazon Capabilities by Region
The speed at which Lambda streams your responses depends on the response size. The streaming rate for the first 6 MB of your function’s response is uncapped. For responses larger than 6 MB, 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 incur cost and streamed responses are not interrupted or stopped when the invoking client connection is broken. Customers will be billed for the full function duration, so customers should exercise caution when configuring long function timeouts.
Lambda supports response streaming on Node.js managed runtimes. For other languages, including Python, you can use a
custom runtime with a custom Runtime API integration to stream responses or use the Lambda Web Adapter
Note
When testing your function through the Lambda console, you'll always see responses as buffered.
Topics
Bandwidth limits for response streaming
The first 6 MB of your function’s response payload has uncapped bandwidth. After this initial burst, Lambda streams your response at a maximum rate of 2 MBps. If your function responses never exceed 6 MB, then this bandwidth limit never applies.
Note
Bandwidth 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 2 MBps for the first 6 MB of your function’s response. If your function is streaming a response to a destination outside of Amazon, the streaming rate also depends on the speed of the external internet connection.
VPC compatibility with response streaming
When 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 Amazon SDK using the
InvokeWithResponseStreamAPI. 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