I want to read zip file from local in Node JS (Also I would be hosting this backend on Linux based server) In the below code, exampleLambda.zip file is in the same folder where the .js code file exists.
const zipContents = fs.readFileSync('exampleLambda.zip');
var params = {
Code: {
// here at below I have to pass the zip file reading it from the S3 public bucket
ZipFile: zipContents,
},
FunctionName: 'testFunction', /* required */
Role: 'arn:aws:iam::149727569662:role/ROLE', /* required */
Description: 'Created with tempalte',
Handler: 'index.handler',
MemorySize: 256,
Publish: true,
Runtime: 'nodejs12.x',
Timeout: 15,
TracingConfig: {
Mode: "Active"
}
};
lambda.createFunction(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
while reading the file it throws error Error: ENOENT: no such file or directory, open 'exampleLambda.zip
error I have also tried with
const zipContents = fs.readFileSync('./exampleLambda.zip');
The file is in the same folder where the .Js file exists.
Why this throws an error, I am using fs lib from nodeJS. Is there any way around for this? Also, I want a solution where It also works on the server as well which is a Linux base because I am gonna upload it there.