Closed
Description
Expected behavior
Is it possible to stream a full HTTP response (with custom headers and status code), when the function is invoked via its function URL (https://123xyz.lambda-url.us-east-1.on.aws/)?
Specifically, this code already works:
struct EchoStreamer: StreamingLambdaHandler {
// Raw event (from the URL request) we don’t need here
typealias Event = String
// Per-chunk type; ByteBuffer keeps allocations low
typealias StreamChunk = ByteBuffer
func handle(_ event: ByteBuffer, responseWriter: some LambdaResponseStreamWriter, context: LambdaContext) async throws {
let eventString = String(buffer: event)
for character in eventString {
try await responseWriter.write(.init(string: String(character)))
try await Task.sleep(nanoseconds: 10_000_000)
}
try await responseWriter.finish()
}
}
try await LambdaRuntime(handler: EchoStreamer()).run()
but, is it possible to set the status code and headers of the response?
Currently, running
curl -N -v --header "Content-Type:\ application/json" --data "{\"name\":\"Alice\"}" https://123xyz.lambda-url.us-east-1.on.aws/
does echo the request body back as a stream, but the status code and headers are set by AWS
Actual behavior
_
Steps to reproduce
_
If possible, minimal yet complete reproducer code (or URL to code)
_
What version of this project (swift-aws-lambda-runtime
) are you using?
main
Swift version
6.0
Amazon Linux 2 docker image version
amazonlinux2