lambda找不到我的node_modules

Mon*_*key 3 amazon-web-services aws-lambda

我正在尝试使用我的lambda上传node_modules但我收到"Cannot find module"错误.

我已经设置了一个真正简单的hello world js文件

var async = require('async');
Run Code Online (Sandbox Code Playgroud)

我已经手动将node_modules/async文件夹复制到发行版中 - 然后我将node_modules文件夹与hello world js文件一起复制.

我的照片缩放器lambda做了一个非常类似的事情,它也采用了节点模块,并且可以工作.我做错了什么不同?

gar*_*aat 6

zip文件的结构很重要.假设我有一个javascript函数包含在一个名为的文件中foo.js,该函数依赖于其他节点模块.

在我的开发环境中,我会有这样的结构:

devdir/
    foo/
        foo.js
        node_modules/
            <the nodejs modules>
Run Code Online (Sandbox Code Playgroud)

然后我创建一个名为foo.zip结构的zip文件,如下所示:

$ unzip -vl foo.zip 
Archive:  foo.zip
 Length   Method    Size  Ratio   Date   Time   CRC-32    Name
 -------  ------  ------- -----   ----   ----   ------    ----
       0  Defl:N        0   0%  08-05-15 14:44  00000000  ./
    3047  Defl:N      981  68%  08-05-15 14:25  06e3e178 foo.js
       0  Defl:N        0   0%  08-03-15 13:37  00000000  node_modules/
       0  Defl:N        0   0%  08-03-15 13:37  00000000 node_modules/.bin/
     597  Defl:N      301  50%  03-05-15 14:29  9b0c2ba2  node_modules/.bin/uuid
       0  Defl:N        0   0%  07-16-15 08:32  00000000  node_modules/async/
    3454  Defl:N     1537  56%  06-28-15 18:37  967a5404  node_modules/async/CHANGELOG.md
<...>
Run Code Online (Sandbox Code Playgroud)

确保你的zip文件结构如下,你应该没问题.