“Functions common to several lambda” 可以翻译为 “多个 Lambda 共用的函数”。

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

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.

huangapple
  • 本文由 发表于 2023年7月6日 22:18:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629795.html
匿名

发表评论

匿名网友

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

确定