5

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.

4
  • Its look like you have error in your lambda function related to fs module. Commented Jun 7, 2018 at 10:50
  • Hmm I did not even touch that module / file. Also why would that behave differently just by zipping / unzipping a file? Commented Jun 7, 2018 at 16:32
  • did you try reinstalling those modules? Commented Jun 7, 2018 at 19:52
  • Yes, I did a complete npm install as well which did not change anything unfortunately. Commented Jun 7, 2018 at 21:03

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.