0
votes

When I'm testing on local machine it's working fine, but after I deploy it to lambda, it's not working anymore. It throws this error:

Unable to import module 'handler': Error

at Module._compile (module.js:652:30)

at Object.Module._extensions..js (module.js:663:10)

at Module.load (module.js:565:32)

at tryModuleLoad (module.js:505:12)

at Function.Module._load (module.js:497:3)

I spent a lot of time trying to solve this issue. Please can someone help me with this issue?

1
are you exporting the handler? And can you post a bare minimum example? Without that it is hard to debug. - Aritra Chakraborty
Also, double check if some dependencies are NOT in devDependencies which you are using. And all the packages that are being used are in package.jsons dependencies. - Aritra Chakraborty
which lambda version you are using? - Adiii

1 Answers

1
votes

If you have the structure like:

  |--lambda
  |    `----create.js
  |--serverless.yml

Then try this.

In file serverless.yml:

functions:
    create:
        handler: create.handle

In file, lambda/create.js

module.exports.handle = async event => {
    return "something";
};

check my example code at https://github.com/yogesh-sinoriya/serverless-dynamodb-authorizer