-
Notifications
You must be signed in to change notification settings - Fork 114
[core] Implement Lambda streaming with custom HTTP headers #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Implement Lambda streaming with custom HTTP headers #521
Conversation
970ecef
to
b6fb60c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements Lambda streaming functionality with custom HTTP headers, allowing developers to set HTTP status codes and headers before streaming response bodies. This addresses the need for more control over HTTP response metadata in streaming Lambda functions.
- Adds
StreamingLambdaStatusAndHeadersResponse
struct for configuring HTTP status and headers - Implements
writeStatusAndHeaders
extension method onLambdaResponseStreamWriter
- Updates documentation and examples to demonstrate the new streaming capabilities
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
readme.md | Adds documentation and examples for streaming with HTTP headers |
Sources/AWSLambdaRuntime/LambdaResponseStreamWriter+Headers.swift | Core implementation of headers functionality with response struct and extension methods |
Tests/AWSLambdaRuntimeTests/LambdaResponseStreamWriter+HeadersTests.swift | Comprehensive test suite covering functionality, error handling, and integration scenarios |
Examples/Streaming/Sources/main.swift | Updated streaming examples demonstrating headers usage and conditional responses |
Examples/Streaming/README.md | Enhanced documentation explaining header usage and streaming patterns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
public let statusCode: Int | ||
|
||
/// Dictionary of single-value HTTP headers | ||
public let headers: [String: String]? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason we aren't use swift-http-types here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because there is no dependency on HTTPTypes in this library and I did not want to pull a new dependency just for this. The data format is well controlled. It's between the Swift runtime and the Lambda data plane.
/// Writes the HTTP status code and headers to the response stream. | ||
/// | ||
/// This method serializes the status and headers as JSON and writes them to the stream, | ||
/// followed by eight null bytes as a separator before the response body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any documentation anywhere we can link to that provides a reason for writing 8 null bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is undocumented at the moment I received the information from an SDM in the Lambda service team and I have confirmed by looking at the NodeJS runtime implementation.
https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/HttpResponseStream.js
The value of the "magic" header is here
https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/a5ae1c2a92708e81c9df4949c60fd9e1e6e46bed/src/HttpResponseStream.js#L17
The 8 x 0 bytes are defined here
https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/a5ae1c2a92708e81c9df4949c60fd9e1e6e46bed/src/HttpResponseStream.js#L26
BTW, at the moment, the NodeJS runtime is the only runtime supporting this capability. When we will release the Swift runtime, it will be second to offer this possibility, before all the AWS managed runtime
…ft-aws-lambda-runtime into sebsto/streaming+http-headers
@adam-fowler ready to give it another review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor thing
Fix #520