如何在AWS lambda nodejs上共享我自己的自定义函数



我目前在AWS中有一个项目,其中有几个lambda函数,大多数函数在NodeJS中,我想知道是否有一种方法可以用创建一个lambda层我自己的代码函数我在不同的lambdas中使用它,而没有在npm中发布它,我已经在堆栈中搜索了旧问题question-1 question-2,但这些都没有回答

谢谢你的帮助!

  1. 在本地机器上创建一个名为nodejs的文件夹
  2. 把你的"共享"/nodejs/shared.js
  3. 你可以压缩这个nodejs文件夹并作为一个图层上传
  4. 在你的lambda代码需要共享的.js作为const shared = require('/opt/nodejs/shared.js')

链接:

  • Lambda层:https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
  • 详细指南:https://explainexample.com/computers/aws/aws-lambda-layers-node-app
  • 使用SAM图层:https://docs.aws.amazon.com/serverlessrepo/latest/devguide/sharing-lambda-layers.html

最新更新