简体   繁体   中英

Cannot deploy a NodeJS AWS Lambda Function. Error at Object.fs.openSync

so until a few days ago I used to deploy my Node.JS AWS Lambda functions via a short and simple shell script, which worked perfectly fine.

Now I do not know why or what I have done different, but for some reason after every deploy of my lambda function I now get the following error, when invoking the function via Alexa:

19:47:58
module initialization error Error
module initialization error
Error

19:47:59
START RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d Version: $LATEST
START RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d Version: $LATEST

19:47:59
module initialization error: Error at Object.fs.openSync (fs.js:646:18) 
at Object.fs.readFileSync (fs.js:551:33) 
at Object.Module._extensions..js (module.js:662:20) 
at Module.load (module.js:565:32) 
at tryModuleLoad (module.js:505:12) 
at Function.Module._load (module.js:497:3) 
at Module.require (module.js:596:17) 
at require (internal/module.js:11:18)

module initialization error: Error
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.Module._extensions..js (module.js:662:20)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)

19:47:59
END RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d

19:47:59
REPORT RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d  
Duration: 218.74 ms  Billed Duration: 300 ms 
Memory Size: 128 MB Max Memory Used: 20 MB

REPORT RequestId: 596b2724-68f9-11e8-aaa7-d9ff3044ed9d  
Duration: 218.74 ms Billed Duration: 300 ms 
Memory Size: 128 MB Max Memory Used: 20 MB  

Now here comes the part that really makes me clueless how I could solve this, (and it is probably something local on my Mac, I guess). If I download / export a previously working deployment package from my Lambda function and directly reupload the Zip file, it works .

If I unzip the file and rezip it again , I get the error

without me changing anything about the code. That is what makes me wonder if there is something wrong with the zipping on my mac or maybe the file system?

I am using Mac OSX High Sierra, Node 6.10 / 8.10 via nvm. The code on lambda runs with 6.10 and 8.10

Any suggestions appreciated :)

Edit: The last working commit was done on a windows PC... I am slightly worried whether the file system change somehow breaks the zipping / upload. I will try and have a deeper look into that.

We were uploading a .zip archive of the code to AWS Lambda.

The problem for us was that the files inside the .zip file didn't have world-readable permissions.

Okay, only thing that was able to solve this, was going back to the last commit that I did from OSX and ignoring the last 3 commits that I did on windows.

It looks like there were some path or encoding changes that were introduced by committing on windows which resolved in this error. Unfortunately I cannot see those in the commit diffs.

So looking for differences between operating systems might be important here.

I was facing the same issue. This worked for me on Windows-

  1. export the lambda function (which downloads a .zip file)
  2. extract files
  3. Zip those files again
  4. Upload this new zip to the lambda

I have run into issues with Lambda and code from Windows machines in the past. The solution (for me) was to chmod -R 644 lambdaDirectory from outside the directory, fixing whatever Windows did to the permissions. I have no clue what would cause the download/reupload to work, maybe AWS is doing something to the manifest?

I have also had issues with zip files coming from other machines that use third party compression tools, as they compress the entire directory into an archive named the same instead of just the contents. IE you don't want lambdaDirectory/ to be included in your lambdaDirectory.zip . To solve this, run zip -r lambdaDirectory.zip ./* from inside the directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM