'Invalid ELF Header - Argon2 package

I am running to an error that says "Invalid ELF header" for a package called "argon2". When uploading my code to AWS Lambda through the serverless framework. The code runs perfectly when running locally.

Development on MacOS Big Sur version 11.4

Image of the error I am getting

I've researched a little bit on the error and people are saying to use Docker to compile the packages and then send to Lambda. I haven't worked with Docker much and wanted to explore other options before attempting the docker solution.

Any guidance or help would be much appreciated! I've been stuck on this bug for over a day or two.



Solution 1:[1]

Just to add. To deploy to Lambda you would (eventually) need to send your files in a zip. And to bundle your project efficiently you would need a bundler like Webpack. The problem is, argon2 and any other hash implementations like bcrypt use node-pre-gyp dependency that doesn't work well with bundler. So the options are:

  • Just zip the entire project and everything inside node_modules. This means including everything that isn't used which can be massive.
  • When using Webpack exclude argon2 from the config with the consequence that it has to be manually installed in target environment.
  • Use a pure js version of argon2 which is much slower.
  • If you use it to manage passwords then you can drop it for a cloud service like AWS KMS that offers secure symmetric keys. However these keys encrypt, not hash so for the better or worse you can decrypt the passwords back to plain text.

Remember that hashing performance itself is proportional to memory and CPU. So running a hashing algorithm for fast result could mean high Lambda bill.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1