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.
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.
Make sure you're not zipping the folder, but its contents. Check that your zip contains index.js
in its root level
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With