Skip to content

Commit 621e975

Browse files
committed
revert streaming+codable
1 parent a5ff8e5 commit 621e975

File tree

5 files changed

+38
-118
lines changed

5 files changed

+38
-118
lines changed

Examples/StreamingFromEvent/Package.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ let package = Package(
1010
platforms: [.macOS(.v15)],
1111
dependencies: [
1212
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
13-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "2.0.0-beta.1")
13+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "2.0.0-beta.1"),
14+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
1415
],
1516
targets: [
1617
.executableTarget(
1718
name: "StreamingFromEvent",
1819
dependencies: [
19-
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
20+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
21+
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
2022
]
21-
)
23+
),
24+
.testTarget(
25+
name: "StreamingFromEventTests",
26+
dependencies: [
27+
"StreamingFromEvent",
28+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
29+
]
30+
),
2231
]
2332
)
2433

Examples/StreamingFromEvent/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
# Streaming Codable Lambda function
22

3-
This example demonstrates how to use the `StreamingLambdaHandlerWithEvent` protocol to create Lambda functions that:
3+
This example demonstrates how to use a `StreamingLambdaHandlerWithEvent` protocol to create Lambda functions, exposed through a FunctionUrl, that:
44

55
1. **Receive JSON input**: Automatically decode JSON events into Swift structs
66
2. **Stream responses**: Send data incrementally as it becomes available
77
3. **Execute background work**: Perform additional processing after the response is sent
88

9-
The example uses the streaming codable interface that combines the benefits of:
9+
## When to Use This Approach
10+
11+
**⚠️ Important Limitations:**
12+
13+
1. **Function URL Only**: This streaming codable approach only works with Lambda functions exposed through [Lambda Function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html)
14+
2. **Limited Request Access**: This approach hides the details of the `FunctionURLRequest` (like HTTP headers, query parameters, etc.) from developers
15+
16+
**Decision Rule:**
17+
18+
- **Use this streaming codable approach when:**
19+
- Your function is exposed through a Lambda Function URL
20+
- You have a JSON payload that you want automatically decoded
21+
- You don't need to inspect HTTP headers, query parameters, or other request details
22+
- You prioritize convenience over flexibility
23+
24+
- **Use the ByteBuffer `StreamingLambdaHandler` approach when:**
25+
- You need full control over the `FunctionURLRequest` details
26+
- You're invoking the Lambda through other means (API Gateway, direct invocation, etc.)
27+
- You need access to HTTP headers, query parameters, or request metadata
28+
- You require maximum flexibility (requires writing more code)
29+
30+
This example balances convenience and flexibility. The streaming codable interface combines the benefits of:
1031
- Type-safe JSON input decoding (like regular `LambdaHandler`)
1132
- Response streaming capabilities (like `StreamingLambdaHandler`)
1233
- Background work execution after response completion

Sources/AWSLambdaRuntime/LambdaStreaming+Codable.swift renamed to Examples/StreamingFromEvent/Sources/LambdaStreaming+Codable.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import AWSLambdaEvents
16+
import AWSLambdaRuntime
1517
import Logging
1618
import NIOCore
1719

@@ -149,8 +151,6 @@ public struct StreamingFromEventClosureHandler<Event: Decodable>: StreamingLambd
149151
}
150152
}
151153

152-
#if FoundationJSONSupport
153-
154154
extension StreamingLambdaCodableAdapter {
155155
/// Initialize with a JSON decoder and handler.
156156
/// - Parameters:
@@ -203,4 +203,3 @@ extension LambdaRuntime {
203203
self.init(handler: adapter, logger: logger)
204204
}
205205
}
206-
#endif // FoundationJSONSupport

Tests/AWSLambdaRuntimeTests/LambdaStreamingCodableTests.swift renamed to Examples/StreamingFromEvent/Tests/LambdaStreamingCodableTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Synchronization
1818
import Testing
1919

2020
@testable import AWSLambdaRuntime
21+
@testable import StreamingFromEvent
2122

2223
#if canImport(FoundationEssentials)
2324
import FoundationEssentials

Sources/AWSLambdaRuntime/FoundationSupport/Vendored/FunctionURL-HTTPType.swift

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)