-
Notifications
You must be signed in to change notification settings - Fork 363
Description
Hey folks!
After looking at how to wrap lambda_runtime::Handler
compared to tower's layers (thanks to @davidbarsky), and @Mdrbhatti's recent PR on making self mutable for Handler
, I'm wondering if we wouldn't benefit from using tower::Service
instead.
The signatures today are pretty close already, with the two differences between the addition of a Response
type and poll_ready
method.
Why should we do this?
We would then benefit from being able to reuse existing (and well-tested) libraries on that side. For me, I'd like to implement a few tools to help with Rust functions on Lambda similar to what we've done for Python and Java, such as creating structured logs, handling tracing, etc. Being able to use layers to wrap the function itself would be quite helpful there.
It could make some of the existing tools such as warp_lambda or poem-lambda simpler too.
Why shouldn't we do this?
I could write my own implementation of layers for my use case. However, before committing to a specific implementation, I want to double-check we're not missing on something by not doing this.
This is also a pretty significant change for the libraries that depends on lambda-runtime or lambda-http. However, We could minimize the impact for most users of this runtime since they usually interact only with lambda_runtime::run
, lambda_runtime::handler_fn
, or lambda_http::handler
. We could keep the same function names but change their signatures.
What would the experience look like?
The least impactful change would be to implement tower::Service
for HandlerFn
, and make run
accept a service.
We'll probably need to create a new type that would handle both the event payload and context at the same time, as Handler.call
take two arguments while tower::Service.call
only takes one.
If people are interested in this, I'm happy to create a proof of concept.