我在尝试在 AWS Cloud9 的 lambda 项目中安装 Node 模块时遇到问题。
我运行了命令
npm install --save request
npm install --save request-promise
我不断收到“错误:找不到模块‘request-promise’”。
我有以下代码。
var rp = require('request-promise');
它的结构是这样的
-Lambda 环境
--获取合并产品
--node_modules
最佳答案
这不是 Lambda 应该使用的方式。 我与一位 AWS 解决方案架构师进行了交谈,他为我指明了方向。
Remember that each function is intended to stand on its own, so it needs to be packaged on its own. Each function would have its own package.json and node_modules as each function runs in its own container(s).
Your approach assumes that all of your functions run on the same infrastructure, which is not the case in the serverless world. Global modules (beyond what is packaged in the Lambda runtime) do not exist.
Be sure to read: https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html and https://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html
我通过将 node_modules 文件夹从环境文件夹移动到 lambda 项目文件夹来测试这一点,它起作用了!
关于node.js - AWS Cloud9 Lambda 安装node.js 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48412315/