After making a deploy, I test the function and show this:

I added the bcrypt module, in local it works, but it does not work when I deploy

errorMessage": "/var/task/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

Hi Dsantacruz and welcome to the community.

The issue you mention is the fact that the environment under which your Lambda functions run on AWS is not the same as the environment you might run locally. Bcrypt has to be compiled for the environment in which it is going to execute since it is written in C and this means if you have to use that specific version there are some hoops you will need to jump through. These instructions should help you with that route:

The alternative is to use a module called bcryptjs ( which does exactly the same thing but is written purely in JavaScript. The downside is that it will be a bit slower but this might be good enough for you.

1 Like

It should be good enough. and it’s not really a downside. The response time of a call to bcrypt is not the premier thing to optimize on.

The funny thing is that bcrypt is designed to be configurably slow. From Wikipedia: bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.

So, even if a brute-force attack on hashed passwords with another implementation might be 30% faster, that effect can be cancelled by increasing the number of hashing rounds by the algorithm.

change package to:
npm install bcryptjs
var bcrypt = require(‘bcryptjs’);

The functions are the same.

Get more information here GitHub - dcodeIO/bcrypt.js: Optimized bcrypt in plain JavaScript with zero dependencies.