AWS Lambda Error: “Cannot find module '/var/task/index'”

后端 未结 9 1699
忘掉有多难
忘掉有多难 2020-12-23 02:54

Node.js Alexa Task Issue

I\'m currently coding a Node.js Alexa Task via AWS Lambda, and I have been trying to code a function that receives informat

相关标签:
9条回答
  • 2020-12-23 03:11

    In my case it was because I had the handler file in inner src directory.

    I had to change the 'Handler' property within Lambda from:

    index.handler
    

    to

    src/index.handler
    
    0 讨论(0)
  • 2020-12-23 03:11

    In my case this was caused by Node running out of memory. I fixed that by adding --memory-size 1500 to my aws lambda create-function ... command.

    0 讨论(0)
  • 2020-12-23 03:15

    I got this error when I was using lambci/lambda:nodejs8.10 in windows.

    I'd tried all of the solution listed above but none of which could help me deal with my issue(even though the error stack look the same as the question).

    Here is my simple solution:

    1. using --entrypoint flag to run a container to find out if the file is mounted into the container. It turns out I may got the share drive issue with my Docker Desktop.
    2. I switched my docker daemon that day before, but everything works fine except this problem.
    3. Anyway, remount my drive to Docker Desktop, you can both use the docker command or just open the Docker Desktop setting to apply.
    0 讨论(0)
  • 2020-12-23 03:18

    Check that file name and handler name are same:

    That means that zip file has bundle.js file that exports handler function:

    exports.handler = (event, context, callback) => {//...}
    
    0 讨论(0)
  • 2020-12-23 03:23

    In my case the archive contained a folder "src" with index.js file, so I had to put to the handler: "src/index.handler"

    0 讨论(0)
  • 2020-12-23 03:26

    Fixed it! My issue was that I tried to zip the file using my Mac's built-in compression function in Finder.

    If you're a Mac user, like me, you should run the following script in terminal when you are in the root directory of your project (folder containing your index.js, node_modules, etc. files).

    zip -r ../yourfilename.zip *
    

    For Windows:

    Compress-Archive -LiteralPath node_modules, index.js -DestinationPath yourfilename.zip
    
    0 讨论(0)
提交回复
热议问题