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). Screen Shot 2016-07-06 at 11.01.28 AM

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.




7 thoughts on “Uploading Node.js package to AWS Lambda

  1. I’m doing exactly as described in your blog but still getting the same issue –
    Unable to import module ‘index’: Error
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17).

    My zip file structure is –

    1. The file should be called index.js and then the handler is the name of the function that gets exported. In other words:

      My zip file structure is –


      exports.handler… in the index.js file.

    1. Hi Diana,
      If your folder structure is like this:
      — / sub_folder

      index.js just needs to be at the root level (like above)

Leave a Reply

Your email address will not be published. Required fields are marked *