aws api gateway & lambda: multiple endpoint/functions vs single endpoint

后端 未结 5 1081
迷失自我
迷失自我 2020-12-07 13:48

I have an AWS api that proxies lamba functions. I currently use different endpoints with separate lambda functions:

api.com/getData --> getData
api.com/ad         


        
5条回答
  •  猫巷女王i
    2020-12-07 14:48

    i've been building 5~6 microservices with Lambda-API Gateway, and been through several try & failure and success.

    in short, from my experiences, it's better to delegate all the API calls to lambda with just one APIGateway wildcard mapping, such as

    /api/{proxy+} -> Lambda
    

    if you ever used any frameworks like grape you know that when making APIs, features like
    "middleware"
    "global exception handling"
    "cascade routing"
    "parameter validation"

    are really crucial. as your API grows, it's almost impossible to manage all the routes with API Gateway mapping, nor API Gateway support non of those feature also.

    further more, it's not really practically to break lambda for each endpoints for development or deployment.

    from your example,

    api.com/getData --> getData  
    api.com/addData --> addData  
    api.com/signUp --> signUp  
    

    imagine you have data ORM, User authentication logic, common view file (such as data.erb).. then how you gonna share that?

    you might can break like,

    api/auth/{+proxy} -> AuthServiceLambda  
    api/data/{+proxy} -> DataServiceLambda  
    

    but not like "per endpoint". you might can lookup concept of microservice and best practice about how you can split the service

    for those web framework like features, checkout this we just built web framework for lambda since i needed this at my company.

提交回复
热议问题