阅读背景:

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

来源:互联网 

I am new to aws and just started working around with aws lambda by following some youtube tutorials and was able to write aws lambda functions successfully on the web editor itself.

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

But I tried with the uploading zip file from my local system in which i wrote a node.js code that use modules "fs" and "fill-pdf". But when I tried to run the code it was giving me error.

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

"error" : module not found "/var/task/index". I searched through internet and found some links like : https://github.com/lob/lambda-pdftk-example I tried this but it also shows same error.

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

Here is my code :

这是我的代码:

    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.');
    });
     }
   });

The thing is that I don't know what could be the reason that this error is coming.Thanks for any help.

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

4 个解决方案

#1


27  

Make sure you're not zipping the folder, but its contents. Check that your zip contains index.js in its root level

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

#2


2  

The error may occur due to the following :

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

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)

#3


0  

Remove the line var index = require('index'); as it is not used in your code. I'm not sure why it can't find the module after installing it, but in you current example you don't need it.

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

#4


0  

This error occurs it means your zip is not in valid form in which aws demands.

发生此错误意味着您的zip不是aws要求的有效形式。

If you double click on zip you will find your folder inside that your code file,but lambda wants that when you double click on zip it shoud show direct code files.

如果您双击zip,您将在您的代码文件中找到您的文件夹,但lambda希望当您双击zip时,它会显示直接代码文件。

To achive this:

为了达到这个目的:

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

then upload index.zip to lambda

然后将index.zip上传到lambda


分享到: