How can I stream plain-text responses from Java AWS Lambda?

September 16, 2026 3 answers
Asked by Benchwarmer
AWS Lambda Java response streaming appears to expect a JSON-compatible response. The handler exposes an OutputStream, so I tried writing raw bytes directly with `output.write("SSSSSSSSSSSSSSSSSSS".getBytes())`, but the Function URL returned an Internal Server Error. Wrapping the same text in a JSON array, such as `["SSSSSSSSSSSSSSSSSSS"]`, worked. Buffered Java responses under 6 MB already work, and Node.js streaming also works, but I'm trying to stream larger responses from the Java runtime through a Function URL. Is Java response streaming supported, or is there a required response format or different configuration?

Answers

somewhat~organized
The JSON-wrapped version working suggests Lambda is successfully interpreting the response envelope, while the plain text is not being handled as a valid response for the invocation path youโ€™re using. Writing bytes to an OutputStream alone may not be enough; the streaming-specific integration has to be enabled and used rather than a normal buffered Function URL response.
Reply to this answer
rural bus timetable
Iโ€™d also check the Lambda logs for the actual Internal Server Error. Changing Java versions and CPU architecture probably wonโ€™t affect this if the issue is an unsupported response mode, but the logs should confirm whether the failure is coming from serialization, the Function URL integration, or the streaming protocol.
Reply to this answer
beam_0p8
The managed runtime documentation has historically shown response streaming primarily for Node.js, while buffered responses are documented for more runtimes. If Java streaming is not supported by the managed Java runtime, you may need a custom runtime or adapter that implements Lambdaโ€™s streaming protocol. Otherwise, Java will likely need to use buffered responses or return a JSON-compatible value.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions