Search code examples
node.jsaws-lambdaserverless

serverless - node.js crypto package is not working


Trying to generate RSA keys with crypto package and deploy it on AWS Lambda, I get an error that crypto package is undefined. Are there easy ways to deploy this package to Lambda without having building docker containers?

Yes, I read that node.js native packages have different binaries on mac (my current os) and linux, so there is an approach to build docker and deploy it, but I found it's not very clear for me, so if this is the only way to do it, maybe there are good resources to read about it also.

Thanks!


Solution

  • I tried to avoid docker as well but it's actually pretty easy to setup. Install the Community Edition

    Pull this image with this:

    docker pull lambci/lambda
    

    To mount your dev folder run this:

    docker run -v ~/[mydev-folder]:/var/task  lambci/lambda:nodejs8.10
    

    Open Kitematic from the Docker app. You should see the container you pulled. Select it and start it if it's not started. Then click "Exec" and you should get a bash prompt opened in /var/task which should be pointing at your dev folder.

    I usually delete node_modules and then run npm install from inside the docker container. I also sls deploy from there was well.