aws lambda_AWS Lambda和Node JS的路由管理框架

aws lambda

什么是路由管理框架? (What is a Route Management Framework?)

Most software engineers who’ve built and delivered production software have encountered the need for route management frameworks. These frameworks are designed and built to ease the development & management of REST APIs inside NodeJS-based applications.

大多数已经构建和交付了生产软件的软件工程师都遇到了对路由管理框架的需求。 这些框架的设计和构建是为了简化基于NodeJS的应用程序内部REST API的开发和管理。

Image for post
Traditional route management framework inside an API application
API应用程序内的传统路由管理框架

The most popular use of route management frameworks is that they enable us to express ROUTES that our REST APIs expose to consuming parties (web apps, backend workers, customer applications) and assign them a specific execution logic on how to handle requests that were received by our servers.

路由管理框架最流行的用途是使我们能够表达 REST API公开给使用方(Web应用程序,后端工作程序,客户应用程序)的ROUTES ,并为它们分配有关如何处理由接收方接收的请求的特定执行逻辑 。我们的服务器。

Some of the most popular route management frameworks in NodeJS are Express JS, Restify, Fastify, Loopback, Hapi JS, Koa, Loopback, etc.

NodeJS中一些最流行的路由管理框架是Express JS,Resify,Fastify,Loopback,Hapi JS,Koa,Loopback等。

无服务器路由管理框架 (Serverless Route Management Frameworks)

To ease the learning curve and migration efforts that organizations have to face in adopting serverless-based development, different RMF frameworks provided a way to port existing applications to lambda-based architectures which we can call Serverless Route Management Frameworks.

为了缓解组织在采用基于无服务器的开发中必须面对的学习曲线和迁移工作,不同的RMF框架提供了一种将现有应用程序移植到基于lambda的体系结构的方法,我们可以将其称为无服务器路由管理框架。

Image for post
Think of serverless route management frameworks as code-level routers running inside your lambda functions
将无服务器路由管理框架视为运行在lambda函数内部的代码级路由器

Now that we have a better understanding of route management frameworks (RMF), we can start exploring which frameworks are available in serverless-based architectures and which of their traits make them stand out in the selection process.

现在我们对路由管理框架(RMF)有了更好的了解,我们可以开始探索哪些框架在基于无服务器的体系结构中可用,以及它们的哪些特征使其在选择过程中脱颖而出。

Image for post
https://www.npmjs.com/package/aws-serverless-express https://www.npmjs.com/package/aws-serverless-express

AWS无服务器Express (AWS Serverless Express)

Express JS has served the NodeJS community well for years and stayed as the most popular RMF for a long while. No wonder AWS Labs built a routing framework for this wonderful framework. If you are interested in learning more about this framework, I’ve recently written an article that explained the pros & cons of using it.

Express JS多年来一直为NodeJS社区提供良好的服务,并且长期以来一直是最受欢迎的RMF。 难怪AWS Labs为此出色的框架构建了路由框架。 如果您有兴趣了解有关此框架的更多信息,我最近写了一篇文章 ,解释了使用该框架的利弊。

Strengths

长处

  • Elite framework in the NodeJS community

    NodeJS社区中的Elite框架
  • Its popularity makes the hiring of developers easier

    它的受欢迎程度使开发人员的雇用更加容易
  • Tons of articles & sample projects on top of this framework

    在此框架之上的大量文章和示例项目
  • Built by AWS Labs so you can be assured of its continuity

    由AWS Labs构建,因此可以确保其连续性
  • Offers a low learning-curve for developers with Express background

    为具有Express背景的开发人员提供较低的学习曲线
  • Good for migration of existing workloads

    适合迁移现有工作负载
  • Strong usage metrics on NPM (200K+)

    强大的NPM使用量指标(200K +)

Weaknesses

弱点

  • Not popular for async/await syntax

    异步/等待语法不流行
  • Catching errors is not so easy

    捕捉错误并非易事
  • Built on top of external dependencies which bloats the framework

    建立在使框架膨胀的外部依赖项之上
  • Coldstart can be a challenge

    冷启动可能是一个挑战
Image for post
https://www.npmjs.com/package/lambda-api https://www.npmjs.com/package/lambda-api

Lambda API (Lambda API)

This is my personal favorite in our serverless RMF list as it strikes a perfect balance in terms of size-in-bytes & feature set. It also has no underlying dependencies which make it safe from dependency hell issues and lighter than its competitors.

在无服务器RMF列表中,这是我个人的最爱,因为它在字节大小和功能集方面达到了完美的平衡。 它也没有底层依赖,因此可以避免依赖地狱问题,并且比竞争对手轻。

Fun Fact: It was written by the Lebron James of the Serverless field (Jeremy Daly). I would highly recommend checking out his Github repositories and podcast if you are looking into building awesome serverless applications for AWS.

趣闻:这是由无服务器领域的勒布朗·詹姆斯( Jeremy Daly )撰写的。 如果您正在考虑为AWS构建出色的无服务器应用程序,我强烈建议您查看他的Github存储库和播客

Strengths

长处

  • Standalone & does not have any dependency

    独立且没有任何依赖性
  • Good for greenfield projects

    适合新建项目
  • Sleek and sweet API Syntax

    流畅甜美的API语法
  • Native async/await out of the box

    本机异步/等待开箱即用
  • Built by Jeremy Daly of Serverless Chats

    无服务器聊天的 Jeremy Daly构建

  • Boasting an upward usage trend in NPM

    NPM使用量呈上升趋势

Weaknesses

弱点

  • 14 contributors in Github. This is a good investment of your time if you are willing to do some volunteer work!

    Github的14位贡献者。 如果您愿意做一些志愿工作,这是您宝贵的时间!
  • Requires learning curve to be utilized in migration projects

    要求学习曲线可用于迁移项目
  • Slower migration compared to serverless-variants of established RMFs

    与已建立RMF的无服务器版本相比,迁移速度更慢
Image for post
https://www.npmjs.com/package/serverless-http https://www.npmjs.com/package/serverless-http

无服务器HTTP (Serverless HTTP)

Serverless HTTP is an open-source framework that allows wrapping of existing APIs for serverless use without requiring any significant amount of changes.

无服务器HTTP是一个开放源代码框架,该框架允许包装现有API以供无服务器使用,而无需进行大量更改。

If you are in the stage of exploring the feasibility and impact of migration for your APIs and your organization has existing APIs on different RMFs, this framework would contribute positively to migrating your diversified API portfolio by reducing research and implementation time due to the standardized integration mechanism with different RMFs.

如果您正在探索迁移API的可行性和影响的阶段,并且您的组织在不同的RMF上已有现有的API,那么由于采用了标准化的集成机制,该框架将通过减少研究和实施时间来为迁移您多样化的API产品组合做出积极贡献。具有不同的RMF。

On the other hand, I would suggest doing a responsible & thorough benchmarking and behavioral check on your APIs before deciding if its a GO or NO. The framework is known for its support of several RMF frameworks which means that it might contain some dependencies related to other RMFs that you are not interested in.

另一方面,建议您在确定API是否合格之前,对API进行负责任且彻底的基准测试和行为检查。 该框架以其对多个RMF框架的支持而闻名,这意味着它可能包含一些与您不感兴趣的其他RMF相关的依赖项。

Strengths

长处

  • Jack of all RMFs (Good old Swiss Knife Tech)

    所有RMF的杰克(好旧的瑞士刀技术)
  • Supports 3 major old-school RMFs at the time of writing (KOA, Connect, Express)

    在撰写本文时支持3种主要的老式RMF(KOA,Connect,Express)
  • Supports 7 other RMFs at the experimental stage (Restana, Sails, Hapi, Fastify, Restify, Polka, Loopback)

    在实验阶段还支持其他7种RMF(Restana,Sails,Hapi,Fastify,Restify,Polka,Loopback)
  • NPM usage trend is rising nicely

    NPM使用趋势呈上升趋势
  • Good for migration of existing APIs compatible with it

    适合迁移与其兼容的现有API
  • Offers a lower learning-curve for developers familiar with selected RMF

    为熟悉特定RMF的开发人员提供较低的学习曲线

Weaknesses

弱点

  • Support to multiple RMFs make it innately heavier

    对多个RMF的支持使其本来就更重
  • The extra bit of work when searching for code samples

    搜索代码样本时的额外工作
  • Coldstart can be a challenge due to codebase & dependency size

    由于代码库和依赖项的大小,冷启动可能是一个挑战
  • Not ideal for most greenfield projects

    对于大多数未开发项目而言并不理想
Image for post
https://www.npmjs.com/package/lambda-serverless-api https://www.npmjs.com/package/lambda-serverless-api

Lambda无服务器API (Lambda Serverless API)

This RMF is an interesting one as it was documented in Github as a “Middleware for AWS Lambda and API gateway”, I always like to call it as RMF with awesome HTTP verb support, sweet APIs, and cool integrations.

这个RMF非常有趣,因为它在Github中被记录为“ AWS Lambda和API网关的中间件”,我一直喜欢将其称为RMF,它具有出色的HTTP谓词支持,可爱的API和出色的集成。

Strengths

长处

  • Good for greenfield projects

    适合新建项目
  • Decent NPM usage trend

    良好的NPM使用趋势
  • Sweet and sleek APIs

    甜美时尚的API
  • In-memory & S3-based rate limiting

    内存和基于S3的速率限制
  • Swagger integration

    Swagger整合

Weaknesses

弱点

  • 9 contributors in Github

    Github的9位贡献者
  • Heavier than a usual RMFs due to its dependencies with AWS SDK, Swagger

    由于其与AWS开发工具包Swagger的依赖关系,因此比常规RMF重
  • Expect a steeper learning curve when utilized in migration projects

    在迁移项目中使用时,期望学习曲线更陡峭
  • Slower migration compared to serverless-variants of established RMFs

    与已建立RMF的无服务器版本相比,迁移速度更慢
  • Coldstart can be a challenge due to codebase & dependency size

    由于代码库和依赖项的大小,冷启动可能是一个挑战
Image for post
https://www.npmjs.com/package/hapi-lambda https://www.npmjs.com/package/hapi-lambda

哈皮·兰达(Hapi Lambda) (Hapi Lambda)

Just like Express JS & KOA, this is another serverless implementation for easing migration of existing HAPI-based API workloads to the serverless paradigm. HAPI was boasting more built-in APIs (eg. Form Handling) compared to what Express JS can offer.

就像Express JS和KOA一样,这是另一种无服务器的实现,可简化现有基于HAPI的API工作负载向无服务器范式的迁移。 与Express JS相比,HAPI拥有更多内置API(例如,表单处理)。

Fun Fact: HAPI was originally built on top of Express JS and was made to be standalone due to some challenges with Express JS. It was also built by Walmart for special shopping events like Black Friday Sale.

有趣的事实: HAPI最初是在Express JS之上构建的,由于Express JS的一些挑战,使其成为独立的。 它也是由沃尔玛建造的,用于特殊购物活动,例如黑色星期五销售。

Strengths

长处

  • Easier migration of HAPI-based APIs

    基于HAPI的API更容易迁移
  • Simple integration with the Lambda function’s entry point

    与Lambda函数的入口点轻松集成
  • Lower adaption/learning curve for organizations with developers familiar with HAPI

    具有熟悉HAPI的开发人员的组织的适应/学习曲线较低

Weaknesses

弱点

  • Immature at the time of writing

    写作时还不成熟
  • 87 downloads per week at NPM

    NPM每周87次下载
  • 18 stars in Github

    Github 18星级
  • Coldstart can be a challenge due to porting of HAPI

    由于HAPI的移植,冷启动可能是一个挑战
  • Slightly harder to utilize in a greenfield project

    在未开发项目中难以利用
Image for post
https://www.npmjs.com/package/aws-serverless-koa https://www.npmjs.com/package/aws-serverless-koa

AWS无服务器KOA (AWS Serverless KOA)

Like Express JS, this is a wrapper of a well known RMF framework named KOA which is built by Express JS framework authors and designed to be more expressive, smaller, and faster by utilizing async/await syntax with better error-handling.

像Express JS一样,它是由知名JS框架作者构建的,名为KOA的著名RMF框架的包装,该框架通过利用具有更好错误处理能力的 async / await语法, 表现得更强,更小,更快。

Strengths

长处

  • Dead simple integration with KOA

    与KOA的简单集成
  • More of a middleware instead of an RMF

    更多的是中间件而不是RMF
  • Tiny framework

    小框架

Weaknesses

弱点

  • Immature at the time of writing

    写作时还不成熟
  • Low Github star count (20 atm! Show some love guys)

    Github明星人数少(20个大气压!显示一些爱心人士)

  • Low NPM download count per week (330 atm! Show some love guys)

    每周NPM下载量低(330 atm!显示一些爱心人士)
  • 2 Contributors in Github

    Github的2位贡献者
Image for post
https://www.npmjs.com/package/@midwayjs/faas https://www.npmjs.com/package/@midwayjs/faas

MidwayJS-制作中的黑马 (MidwayJS — A Dark Horse in the Making)

Here comes a newborn TypeScript-based RMF. This framework was made by Harry Chen who is a battle-tested serverless veteran within Alibaba & Taobao!

这是新生的基于TypeScript的RMF。 这个框架是由哈里·陈 ( Harry Chen)创建的 ,他是阿里巴巴和淘宝网中经过测试的无服务器资深人士!

What makes this framework shine in the competition is its functional style syntax which just became a hit in Vue 3.0 syntax and was piloted by React hooks!

使该框架在竞争中脱颖而出的是其功能样式语法,该语法在Vue 3.0语法中大受欢迎,并由React挂钩进行了试验!

On top of its mojo, TypeScript syntax, and functional programming style are cool features like IOC & Decorators which makes it cohesive with the projects built on top of newly released VueJS & React Hooks!

除了其Mojo之外,TypeScript语法和函数式编程样式还具有IOC和Decorators等超酷功能,使其与基于新发布的VueJS和React Hooks构建的项目紧密结合!

Strengths

长处

  • Functional Programming Syntax

    功能编程语法
  • Typescript Support

    打字稿支持
  • Inversion of Control (IOC)

    控制反转(IOC)
  • Decoration Syntax

    装饰语法
  • Good for greenfield projects

    适合新建项目
  • Reduced cognitive switching required when working with VueJS 3 & React Hooks

    减少使用VueJS 3和React Hooks时所需的认知转换
  • Extremely lightweight (65KB)

    极其轻巧(65KB)
  • Ease of local invocations

    简化本地调用

Weaknesses

弱点

  • Support for AWS just got released this month

    本月刚刚发布了对AWS的支持

  • Needs to catch up with released RMFs at the time of writing

    在撰写本文时需要赶上已发布的RMF
  • Slower migration compared to serverless-variants of established RMFs

    与已建立RMF的无服务器版本相比,迁移速度更慢

摘要 (Summary)

  • Route management frameworks are code-level routers inside an API application

    路由管理框架是API应用程序中的代码级路由器
  • RMFs existed way before serverless architecture did

    RMF在无服务器架构之前就已经存在
  • RMFs help in easing the learning-curve during an organization’s serverless adoption phase

    RMF帮助缓解组织的无服务器采用阶段的学习曲线
  • Some RMFs ease migration efforts by providing routing syntax familiar to your developers

    一些RMF通过提供开发人员熟悉的路由语法来简化迁移工作
  • Some RMFs are way better utilized on greenfield projects

    一些RMF在新建项目中得到了更好的利用
  • We got acquainted with 7 RMFs

    我们熟悉了7个RMF
  • We’ve seen their strengths and weaknesses

    我们已经看到了他们的优势和劣势
  • Selecting RMFs should be decided on a case-to-case basis

    选择RMF应该视情况而定
  • A dark horse arrived in the form of Midway JS!

    一匹黑马以Midway JS的形式到达!

下一步是什么? (What’s Next?)

The list of strengths and weaknesses listed in this article is purely based on my observations and research around the frameworks. To be more objective in comparing these RMFs, we’re going to perform a data-driven analysis of relevant KPIs and I will post the results I get to collect on my upcoming article.

本文列出的优点和缺点列表纯粹是基于我对框架的观察和研究。 为了更客观地比较这些RMF,我们将对相关的KPI进行数据驱动的分析,我将在接下来的文章中发表收集到的结果。

翻译自: https://medium.com/javascript-in-plain-english/route-management-frameworks-for-aws-lambda-and-node-js-ab685aeec839

aws lambda

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值