- Newest
- Most votes
- Most comments
Based on the available information, AWS Amplify Hosting does not currently natively support streaming responses from Next.js API routes. This explains why your streaming implementation works locally with next dev but fails when deployed to Amplify Hosting, where the entire response is buffered and only sent after completion.
The issue is similar to challenges faced with API Gateway, which also doesn't natively support streaming responses or chunked transfer encoding by default. When you deploy a Next.js application to Amplify Hosting, the underlying infrastructure may be buffering your response rather than streaming it incrementally to the client.
For streaming functionality in AWS environments, there are a few potential workarounds:
-
WebSocket API: While not your preferred solution, implementing a WebSocket API would be the most straightforward way to achieve true streaming behavior in AWS environments.
-
Custom solution at the application level: You could implement a custom streaming solution by breaking your response into smaller chunks and having the client reassemble them, or implementing long-polling techniques.
-
Direct Lambda integration: If your use case allows, you might consider exposing certain streaming functionality directly through AWS Lambda with response streaming capabilities, bypassing some of the Amplify Hosting limitations.
-
Polling mechanism: As an alternative approach, you could implement a polling mechanism where the client periodically checks for updates from the backend.
It's worth noting that even if you manage to get chunked transfer encoding working, there might be timeout limits that could interfere with long-running streams.
There is no publicly available timeline for when Amplify Hosting might add native support for streaming responses from Next.js API routes. For critical streaming requirements, you might need to consider alternative hosting solutions or implement one of the workarounds mentioned above.
Sources
Streaming response from api gateway | AWS re:Post
Streaming Http response from Lambda function with Amplify Gen2 | AWS re:Post
Relevant content
asked 4 years ago
