-
Notifications
You must be signed in to change notification settings - Fork 88
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
RFC: support for multi-endpoint HTTP handler Lambda functions #1612
Comments
Morning @dnnrly ! Thanks heaps for this - it is clear you have spent time thinking about this. There is prior art here too - powertools for python supports something similar . Full disclosure - we are focusing at the moment on getting V2 #1522 into a good state, targeting H1 this year. This is certainly something we'd be interested in in the future, though, and would have a natural home in V2, as we're reluctant to add net new features to V1. |
Sure, that makes sense. I'm in no rush to include this - happy to contribute whenever it makes the most sense. It probably offers this RFC a chance to breathe a little bit and gives us time to get the right kind of feedback. |
absolutely - it would be great to get other views on this pop up in the coming weeks ! |
Thank you @dnnrly for this very well detailed RFC. As Scott mentioned, there is an equivalent in python, and this is a feature we were thinking about when we looked at the feature parity with Python. To be transparent, it was definitely not our number one priority as it's a complex one and also very competitive (vs Spring & other fwks). But I like the idea to have something lighter and the first thoughts you put in this RFC. About this, can we have pre-filters and post-filters (for example to add CORS headers or other data transformation) ? Also, it would be great to see what has been done in Python, not to replicate but to get inspiration and maybe complete the feature scope. |
The filters in this implementation aren't pre- or post-, you can write the code around the call to As for the comparison with other frameworks, our experience with Spring and JaxRS performance was very poor when we tried it. The cold-start times were quite high - beyond our budget for the APIs that we have implemented. It's not really meant to compete with those technologies, just give you options if you want to host your API using lambdas. I totally understand that it's not a priority. I raised this RFC as we have had a stable implementation for a couple of years now and it has become an important part of how we deliver our APIs and it seemed a shame not to share our experience with the wider development community. 😄 |
Thank you very much for your contribution here. Let's sleep on this a bit. v2 is around the corner, then it makes sense to have another look at it. |
Thinking out loud @dnnrly - what would be the downside of providing a powertools implementation of JAX-RS? I don't think it should be inherently slow in and of itself (see e.g. Quarkus). On the other hand from my own perspective I quite like this style of API modelling you've done here - it feels more "modern" to me, and lines up with the way we're using builder-style interfaces in V2 e.g. batch V2 APIpowertools-lambda-java/docs/utilities/batch.md Lines 533 to 545 in adbb7bf
|
@scottgerring remember our conversation on jax-rs: #1103 |
In retrospect I think my suggestion to use quarkus or spring-boot is a bit heavy-handed. I see the value in providing something lightweight like both yourself and @dnnrly are suggesting! I am not sure about the performance impact of it; it feels like quarkus with resteasy-reactive mitigates this somehow (compile time weaving ? 🤷 ). Ultimately I am hoping to prompt new discussion on options ! |
Key information
Summary
This RFC proposes a new module that will allow developers to easily implement lightweight, multi-endpoint ALB and API Gateway lambdas in Java with minimal (or no) additional dependencies outside of the Powertools and the JRE. This approach provides an alternative to using more heavy weight frameworks based around Spring or JaxRS, reducing GC and classloader burden to allow maximum cold start performance.
Motivation
Here's the value statement I think we should work towards:
We have been using a lightweight framework to achieve this goal rather successfully for the past couple of years. We have gone all-in on AWS lambda and have been able to solve many of the problems associated with implementing Java lambdas as we gained experience. We would like to contribute some of the technology that has enabled to do this so successfully.
To be more specific about what problem this solves, this RFC proposes a solution for lambdas that:
Many of the techniques and approaches used in this proposal come from this article:
https://medium.com/capital-one-tech/aws-lambda-java-tutorial-best-practices-to-lower-cold-starts-capital-one-dc1d8806118
This proposal does not make Java more performant than using other runtimes for your lambda, but it does prevent the framework being a performance burden.
Proposal
The design of this proposal is significantly different from the approach taken in Spring and JaxRS. It borrows concepts and idioms from other languages, Go in particular. Despite this it is still possible to use patterns familiar to Java developers such as 3-tier or Domain Driven Design. Examples of this will be shown
API examples
Basic route binding
A simple example of how URL path and HTTP method can be used to bind to a specific handler
Filters
In this section, we will describe how we can add filters that allow us to perform operations on the request object before it is passed to the handler. I've called them
filters
here but we can decide if there's a more appropriate name for this.A simple example of how we can add filters to a binding.
Here is an example of a filter you might want perform some common logging.
Here is an example of how you could do request validation inside of a filter.
Here is how you might implement a simple (or complex) exception mapper using filters.
Dependency Injection
Dependency injection is outside of the scope of this RFC - but this approach is compatible with compile-time DI solutions like Dagger2. Our experience has shown that you retain a high degree of control over what code is executed and the number classes being managed by the class loader, allowing you to manage your cold start phase very well.
Drawbacks
The style of API used here will not be familiar to a lot of Java developers. This may add some cognitive burden to those that would like to adopt this module in their solution.
Rationale and alternatives
Unresolved questions
The text was updated successfully, but these errors were encountered: