Integration of REST API with Lambda

0

Hello, I'm developing a REST API with API GW and Lambda (Java Runtime). What would be the best way to integrate a Rest Resource with a lambda function? Of course I know how it is done technically but I need some architectural advice. At the moment I see three possibilities:

  1. I use quarkus and the EasyRest implementation, as known from the classic Tomcat environment. In other words, Jax-RS.
  2. I write the logic myself that uses the path from the APIGatewayrequest object to determine which class should be called next.
  3. i use a jar with one RequestHandler per resource and use this jar to create as many lambdas as there are resources in my API. The actual logic is integrated as a shared lib in each lambda via a layer. So the lambda itself is just a dumb flow heater connected to the rest of the resource.

Point 1 works, but somehow it doesn't feel right to recreate the complete API in the code - that makes sense in Tomcat, but now we have ApiGateway. Point 2 sounds like pure desperation because there is nothing else ;-) Point 3 sounds kind of right, but leads to a lot of lambdas. Unfortunately, a Lambda can only provide one RequestHandler, otherwise it would be easier. What are your opinions on this?

2 Answers
0

Hi,

Option 3. is probably the way to go if you consider other aspects: Lambda does the "undifferentiating heavyweight lifting" for you (scaling, resiliency, runtime patching, etc.). Additionally, it allow very granular security (per lambda - It is harder to do with any Java AS like Tomcat)

So, you get more time to focus on our application.

Also, Lambda is pure pay-as-you go model: if unused, you don't pay. It would not be the case for Tomcat.

When you get to a high-load steady state, then you may start thinking about going back to a traditional AS-based architecture to optimize your costs via EC2 with FaaS.

Finally, on the number of Lambdas, it is not an issue if you implement from start the right Infra-as-Code tools like CloudFormation or even CDK. CDK will allow you to have a very sophisticated and fully programmatic approach to resource definitions.

Best,

Didier

profile pictureAWS
EXPERT
answered 4 months ago
0

Hi,

Thanks for your reply. This means that my idea from point 3 is a common approach? Our AWS infrastructure is managed with Terraform Enterprise, so creating the Lambdas is not the problem.

Dimitri
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions