Recommended approach for building a Lambda Function to Handle multiple Routes like ExpressJS

0

Hi,

I need to build a serverless API that can handle multiple route paths. In a normal NodeJS application this would be done using ExpressJS or one of the myriad other HTTP Server implementations. My question is what is the recommended approach from a good design perspective in Lambda?

  • I could write a switch case in the lambda to handle the different scenarios
  • I could just write different lambda functions for each of the routes and frontend them with API gateway and try to manage routing in API Gateway. This will get complicated for scenarios like /getItem and /getItem/id
  • I could just use expressJS or one of those frameworks in my Lambda code and let it handle the routing part
  • I found https://github.com/awslabs/aws-serverless-express . Or is this the recommended approach?

I am open to comments, suggestions and recommendations including ideas that may not be listed above.

thanks & regards

AWS
Rohit_S
質問済み 4年前2197ビュー
1回答
0
承認された回答

Hi,

I think starting with aws-serverless-express is a good place to start if you're looking to quickly migrate an existing ExpressJS application. This will make it much easier to get up and running and debugging locally if you are already familiar with ExpressJS.

As your application grows you may want to start looking towards using something a bit more lightweight like middy and breaking up your functions. The idea here is by moving to a more modular approach you'll be able to take advantage of additional API Gateway functionality, follow the principle of least privilege with your policies, and right sizing your lambda functions (ie: lambda-power-tuning).

A good way to get started would be to pick a serverless framework/toolchain. A few worth exploring are:

if it's something small you can start simple and then ramp up as needed.

Edit: I failed to mention; if you are beginning a new project it may be better to look into designing your architecture with serverless in mind, which would be more towards focusing on creating individual lambdas, rather than a single lambda handling multiple routes

AWS
回答済み 4年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ