swift-aws-lambda-runtime icon indicating copy to clipboard operation
swift-aws-lambda-runtime copied to clipboard

[core] Runtime does not support AWS Lambda Streaming specification

Open sebsto opened this issue 5 months ago • 6 comments

Expected behavior

The current version of the runtime allows user handlers functions to return data as a stream. But this is a welcome side effect of the design of the swift runtime. The runtime does not follow the Lambda Runtime API specifications.

As a consequence, it is not possible to return user HTTP headers to a Lambda function URL. Also, it is not possible to interrupt the stream with an error that would be reported to the caller.

Specifically, the Lambda Runtime API specification mandates that a custom runtime return specifics HTTP headers and then use HTTP chunks to return the content See https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html#runtimes-custom-response-streaming

See Rust's implementation here https://github.com/awslabs/aws-lambda-rust-runtime/blob/62a36b04ddfd67000d407d06d0da60f394ca4b36/lambda-runtime/src/requests.rs#L103

Actual behavior

It is not possible to return a custom HTTP header to a function URL or to interrupt the stream in case an error occur

Steps to reproduce

n/a

If possible, minimal yet complete reproducer code (or URL to code)

n/a

What version of this project (swift-aws-lambda-runtime) are you using?

main

Swift version

6.x

Amazon Linux 2 docker image version

No response

sebsto avatar Jun 29 '25 15:06 sebsto

This was reported by @jpenwith at https://github.com/swift-server/swift-aws-lambda-runtime/issues/515

sebsto avatar Jun 29 '25 16:06 sebsto

Example of client code in JS https://ravensmove.com/aws-lambda-function-response-streaming https://www.presidio.com/introduction-to-response-streaming-with-aws-lambda/

sebsto avatar Jun 29 '25 16:06 sebsto

Blog from Julian, with more hints about content chunks https://aws.amazon.com/blogs/compute/introducing-aws-lambda-response-streaming/ https://github.com/aws-samples/serverless-patterns/tree/main/lambda-streaming-sdk-sam

sebsto avatar Jun 29 '25 16:06 sebsto

This is the NodeJS Lambda runtime implemntation

HTTP response Stream https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/HttpResponseStream.js

ResponseStream https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/ResponseStream.js

sebsto avatar Jun 29 '25 16:06 sebsto

Thanks, those examples are really useful! I didn’t realize it was an AWS issue

jpenwith avatar Jun 29 '25 17:06 jpenwith

It's not an AWS issue. It is possible for the Lambda function developer to send custom HTTP headers with streaming functions. AWS supports it through their NodeJS runtime and custom runtimes. So it is up to us to make it work now in the Swift runtime.

sebsto avatar Jun 29 '25 18:06 sebsto