我应该在无服务器应用程序中使用Express.js吗? [英] Should I be using Express.js in a Serverless app?

查看:65
本文介绍了我应该在无服务器应用程序中使用Express.js吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在无服务器应用程序(AWS Lambdas)中将Express.js用作中间件是否是一个好主意?我担心的是,在Express.js中存在一个单一功能的设置,将来如果有很多请求进入,它将开始节流.我的担忧是正确的,还是我什么都没动摇.

I wanted to know if using Express.js as middleware in a Serverless app (AWS Lambdas) a good idea? My concern comes from the fact that in Express.js there is a mono-function setup and in future if lots of request come in it'll start throttling. Are my concerns valid or I am wavering about nothing.

推荐答案

在构建单lambda和每个端点一个功能之间的决策并没有明确的答案.

The decision between building a mono-lambda and one-function-per-endpoint does not have a crystal-clear answer.

一方面,如果您使用的是云形成,那么每个堆栈最多只能使用200个资源,这会使单路单lambda设计的小API变得笨拙,并迫使您走下坡路堆栈拆分,该方法有效,但在确实不应该存在的情况下增加了复杂性.此外,由于每个lambda函数都是其自己的部署程序包,因此共享代码变得更加困难-因此,您需要使用诸如手动包含的共享目录,本地NPM模块或良好的ol'方式复制粘贴之类的东西来共享逻辑您的功能.

On one hand, if you're using cloud formation - you're limited to 200 resources per stack, which can make even small APIs with single-lambda-per-route design cumbersome and force you down the path of things like stack splitting, which works but adds complication when there really shouldn't be one. Additionally, this makes it much harder to share code because each lambda function is its own deployment package - so you need to use things like a manually-included shared directory, local NPM modules, or good ol' fashioned copy-paste to share logic between your functions.

另一方面,如果您选择将所有请求路由到lambda,然后在函数内部使用express来路由请求-您将面临管理API网关通常可以为您处理的一些复杂性(诸如请求模板验证之类的事情),或路由验证,或节流/API使用管理).

On the other hand, if you choose to route all requests to lambda and then use express inside your function to route requests - you're faced with managing some complexity that API Gateway can usually handle for you (things like request template validation, or route validation, or throttling/API usage management).

最终,您可以用任何一种方式构建成功的应用程序-因此,您需要考虑的重要事项是:

Ultimately you can build successful applications either way - so the important things for you to consider are:

  • 您正在考虑支持的API端点的数量
  • 这些终结点的域边界(它们与很多共享代码非常相似吗?还是非常独特且整齐地绑定在它们自己的服务中)
  • 需要节流和请求验证之类的APIGW功能
  • 具有或不具有Express之类框架的开发人员的舒适度.

这篇关于我应该在无服务器应用程序中使用Express.js吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆