AWS Cloud9 Lambda 安装 node.js 个模块

AWS Cloud9 Lambda installing node.js modules

我在 AWS Cloud9 的 lambda 项目中尝试安装节点模块时遇到问题。

我运行命令

npm install --save request
npm install --save request-promise

我不断收到 "Error: Cannot find module 'request-promise'"。

我有以下代码。

var rp = require('request-promise');

它的结构是这样的

-Lambda 环境

--getMergedProducts

--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 项目文件夹来测试它,它成功了!