我目前在AWS中有一个项目,其中有几个lambda函数,大多数函数在NodeJS中,我想知道是否有一种方法可以用创建一个lambda层我自己的代码函数我在不同的lambdas中使用它,而没有在npm中发布它,我已经在堆栈中搜索了旧问题question-1 question-2,但这些都没有回答
谢谢你的帮助!
- 在本地机器上创建一个名为nodejs的文件夹
- 把你的"共享"/nodejs/shared.js
- 你可以压缩这个nodejs文件夹并作为一个图层上传
- 在你的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