Add initializer with LambdaHandler directly with Decodable event and Void output #589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add convenience initializer for
LambdaRuntime
to acceptLambdaHandler
instances withVoid
outputMotivation:
Following PR #581, which added convenience initializers for
LambdaRuntime
to acceptLambdaHandler
instances withEncodable
outputs, there was still a gap for handlers that returnVoid
. This is useful, for example, for AWS event sources like SQS, where theAWSLambdaEvents
package providesSQSEvent
but there's no corresponding output type - handlers simply process messages and returnVoid
.Without this initializer, developers had to manually wrap their handlers with
LambdaCodableAdapter
andLambdaHandlerAdapter
, which was verbose and inconsistent with the new API (similar to what is described in #581)Modifications:
Added a new
init(decoder:handler:)
convenience initializer toLambdaCodableAdapter
inLambda+JSON.swift
that accepts aJSONDecoder
for handlers withVoid
output.Added a new convenience initializer to
LambdaRuntime
that accepts aLambdaHandler
instance withVoid
output directly, handling the wrapping internally.Updated documentation comments to distinguish between handlers with
Void
andEncodable
outputs.Result:
Developers can now initialize
LambdaRuntime
with handlers that returnVoid
using a clean, direct API. This is especially useful for event sources like SQS:This provides API completeness, matching the convenience initializers for handlers with
Encodable
outputs, and delivers better ergonomics for common serverless patterns.