-
Notifications
You must be signed in to change notification settings - Fork 361
Replace lambda_runtime::Handler with tower::Service? #374
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
Comments
While I no longer work for Amazon, I'd like to voice my support for switching to
|
Yes please! Is it more lightweight than bringing in opentelemetry, btw? |
@brainstorm this change is not directly related to tracing/observability, but it makes it easier to do so in the future. If I were to compare the features available in Lambda Powertools for Python, using
These are all possible today, but with an interface that matches other libraries, we could speed up development and/or reuse existing ones. |
I've made a quick POC to showcase what the developer experience would look like. For anyone not interacting with If you want to try for your own code, you can do so by making the following changes in your Cargo.toml file: # For lambda_http
lambda_http = { git = "https://github.com/nmoutschen/aws-lambda-rust-runtime", package = "lambda_http", branch = "tower-service" }
# For lambda_runtime
lambda_runtime = { git = "https://github.com/nmoutschen/aws-lambda-rust-runtime", package = "lambda_runtime", branch = "tower-service" } Please note that this is just a POC, so don't build anything that would depend on that in the long term. |
I built both, the current and the proposed versions using |
@rimutaka that's interesting, but sounds plausible. The
I wouldn't be surprised if the compiler interprets them both as the same thing. Let me check if I can reproduce that on my side. UPDATE: after a quick check, I do get different versions. I used
|
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 forHandler
, I'm wondering if we wouldn't benefit from usingtower::Service
instead.The signatures today are pretty close already, with the two differences between the addition of a
Response
type andpoll_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
, orlambda_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
forHandlerFn
, and makerun
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 whiletower::Service.call
only takes one.If people are interested in this, I'm happy to create a proof of concept.
The text was updated successfully, but these errors were encountered: