Commit e3b74f3
authored
Add initializer with LambdaHandler directly with Decodable event and Void output (#589)
_Add convenience initializer for `LambdaRuntime` to accept
`LambdaHandler` instances with `Void` output_
### Motivation:
Following PR #581, which added convenience initializers for
`LambdaRuntime` to accept `LambdaHandler` instances with `Encodable`
outputs, there was still a gap for handlers that return `Void`. This is
useful, for example, for AWS event sources like SQS, where the
`AWSLambdaEvents` package provides `SQSEvent` but there's no
corresponding output type - handlers simply process messages and return
`Void`.
Without this initializer, developers had to manually wrap their handlers
with `LambdaCodableAdapter` and `LambdaHandlerAdapter`, which was
verbose and inconsistent with the new API (similar to what is described
in #581)
### Modifications:
1. Added a new `init(decoder:handler:)` convenience initializer to
`LambdaCodableAdapter` in `Lambda+JSON.swift` that accepts a
`JSONDecoder` for handlers with `Void` output.
2. Added a new convenience initializer to `LambdaRuntime` that accepts a
`LambdaHandler` instance with `Void` output directly, handling the
wrapping internally.
3. Updated documentation comments to distinguish between handlers with
`Void` and `Encodable` outputs.
### Result:
Developers can now initialize `LambdaRuntime` with handlers that return
`Void` using a clean, direct API. This is especially useful for event
sources like SQS:
```swift
import AWSLambdaEvents
struct MySQSHandler: LambdaHandler {
func handle(_ event: SQSEvent, context: LambdaContext) async throws {
// Process SQS messages
}
}
let runtime = LambdaRuntime(lambdaHandler: MySQSHandler())
```
This provides API completeness, matching the convenience initializers
for handlers with `Encodable` outputs, and delivers better ergonomics
for common serverless patterns.1 parent 9487a09 commit e3b74f3
File tree
1 file changed
+52
-2
lines changed- Sources/AWSLambdaRuntime/FoundationSupport
1 file changed
+52
-2
lines changedLines changed: 52 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
86 | 106 | | |
| 107 | + | |
87 | 108 | | |
88 | 109 | | |
89 | 110 | | |
| |||
161 | 182 | | |
162 | 183 | | |
163 | 184 | | |
164 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
165 | 215 | | |
166 | 216 | | |
167 | 217 | | |
168 | 218 | | |
169 | | - | |
| 219 | + | |
170 | 220 | | |
171 | 221 | | |
172 | 222 | | |
| |||
0 commit comments