如何组织一个Java Lambda Handler项目

huangapple go评论58阅读模式
英文:

How to organize a Java Lambda Handler project

问题

以下是您要翻译的内容:

最近我开始使用Java在AWS Lambda上工作,我需要了解如何正确地构建这样的项目。

我应该为所有的Lambda函数创建一个单独的项目,还是为每个函数创建一个项目?

我目前正在遵循前者,并且已经在一个项目中创建了10个Lambda函数。

为了更快的冷启动、较少的依赖和较小的内存占用,我避免使用Spring Boot和Spring,但是.jar文件的大小已经达到了20MB。

我是在遵循正常的模式,还是有什么方法可以改进我的项目结构(见图片)?

解释:我把所有的处理程序都放在一个项目中,当然AWS会为每个函数指定不同的处理程序。

我还想问,把它们放在一起是好的设计,还是每个Lambda应该有不同的项目/模块。例如:deleteUser、disableUser等。

请指导我如何开始。

谢谢

英文:

I recently started working on AWS Lambda using Java and I need to understand how to properly structure a project like this.

Should I only create a single project for all the lambda functions, or should I create a project for each ?

I am currently following the former, and have created 10 lambda functions in one project.

I have avoided the use of Spring Boot and Spring for quicker cold start, less dependencies and smaller memory footprint, but the .jar size is already 20 MB.

Am I following a normal pattern, or how can I improve my project structure (see image) ?

如何组织一个Java Lambda Handler项目

Explanation: I have put all handlers in a single project and of course AWS will point to different handlers for each function.

I also want to ask, is it good design to keep them together or should I have different projects/modules for each lambda. For instance: deleteUser, disableUser etc.

Please guide me to start.

如何组织一个Java Lambda Handler项目

Thanks

答案1

得分: 2

一个项目包含所有Lambda函数应该是可以的,因为最终Lambda函数需要配置到其各自的处理程序。可以查看类似的stackoverflow线程。

链接:https://stackoverflow.com/questions/49208841/is-it-feasible-to-create-multiple-lambda-functions-java-in-a-jar

关于应用程序内存占用,尝试部署Lambda应用程序并检查冷启动时间和内存占用,因为这两者将在一定程度上决定您的Lambda成本。

像Spring Boot之类的框架往往会导致较长的启动时间。其他你可以考虑的选择包括:

  1. 如果您的应用逻辑足够简单,可以避免使用任何框架,只使用核心Java。

  2. Spring Cloud Function - 您可以将其视为用于开发无服务器应用程序的Spring Boot版本(当然还有更多内容)。

    链接:https://spring.io/projects/spring-cloud-function

  3. 尝试使用Quarks,因为他们声称具有更少的内存占用和应用程序启动时间。

    链接:https://quarkus.io/

英文:

One project for all Lambda functions should be fine as, finally the Lambda Function will need to be configured to its respective Handler. Check this similar stackoverflow thread.

https://stackoverflow.com/questions/49208841/is-it-feasible-to-create-multiple-lambda-functions-java-in-a-jar

For Application Memory footprint, try to deploy the Lambda application and check the cold start times and memory footprint as, these 2 will determine your Lambda costs to an extent.

Frameworks like spring-boot tend to cause longer startup times.Other alternatives you could consider.

  1. If your application logic is simple enough,avoid using any framework and just use core java.

  2. Spring Cloud Function- You could consider this as a spring boot version for developing serverles applications(Ofcourse there is a lot more to it)

https://spring.io/projects/spring-cloud-function

  1. Try Quarks as, they claim to have far lesser memory footprint and application startup times.

    https://quarkus.io/

huangapple
  • 本文由 发表于 2020年3月15日 11:46:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/60689552.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定