英文:
Functions common to several lambda
问题
我有一个在NodeJS下托管在AWS上的项目,我有几个函数希望在多个Lambda函数中使用,而不必复制粘贴。目前,我在构建时运行一个shell脚本来复制所有这些文件,但缺点是我使用的所有包也必须安装在所有这些Lambda函数中。
所以我想知道是否有更干净的方法来做这件事。
附注:构建是通过GitHub Actions完成的。
英文:
I have a project under NodeJS and hosted on AWS, and I have several functions that I would like to use in several lambdas, without having to copy and paste. Currently, I run a shell at build time that copies all these files, but the drawback is that all the packages I use must also be installed in all these lambdas.
So I'd like to know if there's a much cleaner way of doing this or not.
PS: The build is done via Github Actions
答案1
得分: 0
你可以选择:
- 使用Lambda 层,这样你可以冻结依赖版本,减少每个 Lambda 的体积,避免重复的代码基础。它允许你减少在使用它的函数中的重复代码。不过一个缺点是,如果在层内部出了问题,导入的函数都会受到影响。
- 在部署到 AWS Lambda 前,捆绑、缩小和摇树(在 TypeScript 中更容易实现)你的 NodeJS 函数。
英文:
You can either:
-
Use Lambda layers so that you can freeze the dependency versions, reduce the weight of each lambda and avoid repetitive code base. It allows you to reduce the repetitive code on functions that would utilize it. One downside though is that if something gets messed up inside the layers, the importing functions will all get affected.
-
Bundle, minify and treeshake your NodeJS (Easier to implement in TypeScript) functions before deploying them to AWS lambda.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论