API网关,多拉姆达在同一JAR [英] Api Gateway, multiple lambda in the same JAR

查看:198
本文介绍了API网关,多拉姆达在同一JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过API网关和使用lambda实现code在Java中部署一个API套件。它是确定有很多(当然相关,)lambda表达式在一个jar(我假定该怎么做),或者是更好地为每个拉姆达我想部署一个jar? (这将成为一个烂摊子很容易)

I'm trying to deploy an API suite by using Api Gateway and implementing code in Java using lambda. Is it ok to have many ( related, of course ) lambdas in a single jar ( what I'm supposing to do ) or it is better to create a single jar for each lambda I want to deploy? ( this will became a mess very easily)

推荐答案

这确实是一个品味的问题,但也有你要考虑几件事情。

This is really a matter of taste but there are a few things you have to consider.

首先有限制有多大单个拉姆达上传即可(50MB在写作的时候)。
其次,还有一个限制,对所有上传(目前1.5GB)所有code中的总规模。 这些限制可能不适合你的使用情况的问题,但都好做到心中有数。

First of all there are limitations to how big a single Lambda upload can be (50MB at time of writing).
Second, there is also a limit to the total size of all all code that you upload (currently 1.5GB). These limitations may not be a problem for your use case but are good to be aware of.

接下来的事情,你必须要考虑的是,你希望你的开销。 比方说,你部署一个CRUD接口,一个LAMBDA,你从API网关传递action参数,让你知道你想要当你执行lambda函数来执行的操作。 这增加了少量的开销到您的执行,你必须将操作路由到相应的操作。这可能是一个非常快的路由但尽管如此,它增加了CPU周期的函数执行。

The next thing you have to consider is where you want your overhead. Let's say you deploy a CRUD interface to a single Lambda and you pass an "action" parameter from API Gateway so that you know which operation you want to perform when you execute the Lambda function. This adds a slight overhead to your execution as you have to route the action to the appropriate operation. This is likely a very fast routing but nevertheless, it adds CPU cycles to your function execution.

在另一方面,部署同样的瓶子在几个lambda函数会很快让你更接近我前面提到的限制,这也增加了管理开销管理您的lambda函数作为数量的增长。当然,它们可以通过CloudFormation或CLI脚本管理,但它仍然会增加管理开销。

On the other hand, deploying the same jar over several Lambda function will quickly get you closer to the limits I mentioned earlier and it also adds administrative overhead in managing your Lambda functions as that number grows. They can of course be managed via CloudFormation or cli scripts but it will still add an administrative overhead.

我不会说有一个正确和错误的方式来做到这一点。看看你正在做什么,想什么,你会需要管理的部署,并把它从那里。如果你做错了,你总是可以重新开始用另一种方法。

I wouldn't say there is a right and a wrong way to do this. Look at what you are trying to do, think about what you would need to manage the deployment and take it from there. If you get it wrong you can always start over with another approach.

我个人喜欢的非常小的服务lambda表达式是做内部路由和处理的不仅仅是一个单一的操作,但他们仍然是非常小的,专注于任务的特定类型无论是一个CRUD的数据库表或管理选定的几密切相关的操作。

Personally I like the very small service Lambdas that do internal routing and handles more than just a single operation but they are still very small and focused on a specific type of task be it a CRUD for a database table or managing a selected few very closely related operations.

这篇关于API网关,多拉姆达在同一JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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