在aws lambda上传邮政编码时遇到问题

时间:2016-11-23 14:39:22

标签: node.js aws-lambda

我是aws的新手,只是通过一些youtube教程开始使用aws lambda,并且能够在Web编辑器本身上成功编写aws lambda函数。

但是我尝试从我的本地系统上传zip文件,其中我写了一个node.js代码,使用模块" fs"和" fill-pdf"。但是当我试图运行代码时,它给了我错误。

"错误" :找不到模块" / var / task / index"。 我通过互联网搜索,发现一些链接,如:      https://github.com/lob/lambda-pdftk-example 我尝试了这个,但它也显示了同样的错误。

这是我的代码:

    var index = require('index');
    var fillPdf = require("fill-pdf");
    var fs = require('fs');
    var formDate = {
    'Employee Name': 'MyName',
    'Company Name': 'ComapnyName'
     };
    var pdfTemplatePath = "my.pdf";


    fillPdf.generatePdf(formDate, pdfTemplatePath, function(err,   
    output) {
    if ( !err ) {

         fs.writeFile('message.pdf', output, function (err) {
    if (err) throw err;
    console.log('It\'s saved! in same location.');
    });
     }
   });

问题是我不知道这个错误即将发生的原因。谢谢你的帮助。

4 个答案:

答案 0 :(得分:28)

确保您不是压缩文件夹,而是其内容。检查您的zip在其根级别中是否包含index.js

答案 1 :(得分:2)

由于以下原因,可能会发生错误:

1. Properly zip the folder wait for it's zipping process completion and 
 then upload.

2. First run the main.js file locally like using node main.js and check 
 are there any errors showing in the terminal window, if it does then 
 fix them and then upload.

3. Also there must be handler file that lambda needs, which is must 
  so if you have the handler.js file then when in aws lambda you 
 create a lambda function and check the configuration setting there 
 then do update the name of the handler file name with yours like by 
 default it is index.js may be you would have lambda.js do change it 
 with lambda name (example lambda.handler)

答案 2 :(得分:0)

删除代码中未使用的行var index = require('index');。我不确定为什么它在安装后无法找到该模块,但在您当前的示例中,您不需要它。

答案 3 :(得分:0)

  

发生此错误表示您的拉链是   不是aws要求的有效形式。

如果双击zip,你会在你的代码文件中找到你的文件夹,但lambda想要当你双击zip时它会显示直接的代码文件。

  

要实现这个目标:

open terminal  
cd your-lambda-folder 
zip -r index.zip *

然后将index.zip上传到lambda

相关问题