Unable to use any 3rd party module with AWS Lambdas


I am working on a lambda that makes use of modules (async, request, etc)

Sample code:

It works fine (prints test) as long as no 3rd party modules (besides aws-sdk) are required. As soon as I just add a line such as:

It fails with the above error. I have tried calling these modules directly as well by specifying the full path with no luck. It’s like its looking at the wrong directory when calling require.

Dumping process.env in the console yields:

Here’s the module I was working off – evidently this used to work at some point but does not for me.

Ideas? I feel that I am missing some configuration unique to lambdas here.


omg that was painful… Turns out that OSX makes the node_modules folder readable only by the user and AWS cannot read it. Make the node_modules folder and content readable by world and it works. I am not sure if all OSX setups react the same. I am using nvm which may be the culprit.

Update. I used to set all files to 0666 but ran into issues with executables. Here’s a little script that will address things properly. It will set all files to 0666 unless executables or a directory in which case 0777. Run this from within the project folder (do be careful of the implications of not doing so!):

Here’s a script from a question I posted:

Leave a Reply