"invalid ELF header" when using the nodejs "ref" module on AWS Lambda
Solution 1
This happens when you build on one architecture and then attempt to use the same built addon on a different architecture (or platform in some cases).
According to this page, addons may have to be compiled against an Amazon Linux image on EC2 in order for the compiled addons to be usable on their Lambda service.
Solution 2
This doesn't apply exactly to your question, but in case anyone stumbles across this when using AWS Elastic Beanstalk, it could be a result of uploading the node_modules/
directory along with everything else, so you need to force it to ignore the file.
.ebignore
node_modules/
Solution 3
For those Developers porting JS to TypeScript on Lambda, ensure ALL dependancies are imported, not required:
import $ from "cheerio";
NOT
const $ = require("cheerio");
seaders
Updated on September 15, 2021Comments
-
seaders over 2 years
I've just uploaded a zip to AWS Lambda which included the "ref" (https://www.npmjs.com/package/ref), which is needed to validate an iOS Game Center authentication token (How to authenticate Game Center User from 3rd party node.js server).
Unfortunately invoking it results in the "invalid ELF header" error,
{ "errorMessage": "/var/task/node_modules/ref/build/Release/binding.node: invalid ELF header", "errorType": "Error", "stackTrace": [ "Module.load (module.js:356:32)", "Function.Module._load (module.js:312:12)", "Module.require (module.js:364:17)", "require (module.js:380:17)", "bindings (/var/task/node_modules/ref/node_modules/bindings/bindings.js:76:44)", "Object.<anonymous> (/var/task/node_modules/ref/lib/ref.js:5:47)", "Module._compile (module.js:456:26)", "Object.Module._extensions..js (module.js:474:10)", "Module.load (module.js:356:32)", "Function.Module._load (module.js:312:12)" ] }
This has been developed on a 64bit Macbook Pro running Yosemite which has no problem running the code locally. Googling around for "invalid ELF header" has yielded little to know relevant results and I'm really not sure where to go from here. Would I be better asking this in a node.js area, or is this the relevant area, because it might be an issue with the platform?
-
zeta about 7 yearsGreat information in the link. I just wanted to add that the EC2 instance to spin should be with name similar to (AMI name: amzn-ami-hvm-2016.03.3.x86_64-gp2) based on docs.aws.amazon.com/lambda/latest/dg/…. In case you don't know which one to create.
-
Milan Velebit over 6 yearsHappens too often while using VMs too, so heads-up, solid answer.
-
ascetic652 almost 4 yearsI have been struggling this for a while, thanks for you answer. My initial guess was the EOF line problem because I was doing my development on Windows, and the application runs on AWS Linux container.
-
Julian Wagner about 3 yearsWow that was exactly what happened to me on Lightsail. Webstorm uploaded even though I didn’t want to