If I understand the documentation correctly, I need to build web3.js on AWS Lambda. How can I do that and which version should I use?
npm install web3 locally. On my Mac machine the only issue then was the building of the scrypt package. You can add an install script to your
package.json to build it locally:
"install": "[ -e node_modules/scrypt/build/Release/scrypt.node ] || docker run --rm -v $PWD:/data -w /data node:6 npm install scrypt"
Note: You need docker installed. Solution from https://stackoverflow.com/a/48487001/5887673.
If anyone is still having issues with running web3 > 1.0.0 and you're using SAM local to test it, consider running
sam build --use-container prior to executing the lambda with
sam invoke local .
This will build and install any dependencies inside of a amazon linux container instead of building it locally.
If you are still looking to build web3 on aws lambda, use a combination of serverless framework, serverless-plugin-scripts and docker to prebuild the node modules before deploying, more details here: web3 serverless