Hello everyone. I’m wondering what’s the best practice if you build a AWS REST API that uses different routes. Let’s assume we have 3 routes. One is for product and one for user. Basically example.com/product and example.com/user. Now I also need a GET request for a specific product. The third route is something like example.com/user?id=1
I see three different options.
-
I create a lambda for example.com/product, for example.com/product?id=1 and for example.com/user.
Pro: each lambda has only one responsibility
Contra: I get a lot lambdas for bigger sites and a lot repetition because the database model, connection parameters etc. are the same, only the SQL queries are different. -
I handle everything inside 1 lambda.
Pro: I have one lambda per service.
Contra: I have multiple responsibilities, the code can be very long, hard to test and messy. -
create a Lambda for the user logic and a lambda for the product logic.
Pro: I have well defined domains and I don’t repeat myself too much. I can reuse most of my code. I don’t have so many lambdas.
Contra: I might have several responsibilities and the code can become very long.
My gut feeling says that the third option is the right one but I also like the first approach. I just dislike the repetition on approach one and the fact that I might have 20 lambdas for one application.
Additionally:
Are there best practices for the naming of lambdas?