Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facing issues when uploaded a zip code in 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.

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.

"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.

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.

like image 996
learner Avatar asked Nov 23 '16 14:11

learner


People also ask

Where are Lambda ZIP files stored?

It should be stored in the same directory as your Lambda handler function. They should be bundled in a zip file and deployed to AWS. If you didn't deploy it that way then that file doesn't currently exist.


2 Answers

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

like image 78
lyosef Avatar answered Nov 11 '22 23:11

lyosef


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)
like image 2
learner Avatar answered Nov 11 '22 23:11

learner