node.js - AWS Cloud9 Lambda 安装node.js 模块

标签 node.js amazon-web-services promise aws-lambda aws-cloud9

我在尝试在 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/

相关文章:

node.js - 端口 34037 已在使用 Heroku + Nodejs + Express + WebSockets

amazon-web-services - 如何只允许少数IP访问AWS网络负载均衡器?

javascript - 是否等待 .catch 完成

javascript - 如何让 Promise 在已经解决时不重新运行代码?

javascript - 在 forEach 循环中创建 promise 并在不嵌套的情况下使用它们

javascript - chaiHttp 忽略端口

javascript - 在没有 I/O 的情况下,javascript(在浏览器中)的异步/ promise 是否有益?

node.js - mongodb $where 查询对于 nodejs 始终为真

amazon-web-services - AWS - 在现有 VPC 中创建公有子网

javascript - 使用 Cognito 用户池向 AWS AppSync 验证 Apollo 客户端