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

我是aws的新手,刚刚开始通过遵循一些YouTube教程来解决aws lambda,并且能够在Web编辑器上成功地编写aws lambda函数。

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

“错误”:找不到模块“/ var / task / index”。 我通过互联网search,发现一些链接,如: 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.'); }); } }); 

问题是,我不知道这个错误是什么原因。谢谢你的帮助。

确保你没有压缩文件夹,但它的内容。 检查您的zip文件是否在其根目录下包含index.js

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

 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) 

删除行var index = require('index'); 因为它没有在你的代码中使用。 我不知道为什么它安装后找不到模块,但在你当前的例子中,你不需要它。

这个错误发生,这意味着你的zip不是在有效的forms,其中aws要求。

如果你双击zip文件,你会在你的代码文件中find你的文件夹,但是lambda希望当你双击zip文件时,它会显示直接的代码文件。

为了达到这个目的:

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

然后将index.zip上传到lambda