Uploading Node.js package to AWS Lambda

Quick tip: for those developing AWS Lambda applications using Node.js, if you're uploading a zip package rather than editing inline, something you might get stuck on while trying to test your function is the below error:

Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17)

First, make sure the name of your handler in the AWS console matches the name of your "main" JavaScript file (the one containing your exports.handler function).

If your file with the exports.handler function is named "index.js", then in the AWS console, name it as "index.handler".

Next, something that really tripped me up was not having this index.js file in the root of my .zip. This was what ultimately led to the Unable to import module 'index' error I kept getting. So make sure this file is in the root of the package.