简体   繁体   中英

Why is my lambda not able to identify dependencies in node_modules?

I have created a lambda pipeline using Github Actions. Part of this pipeline includes zipping and uploading the lambda files and dependencies from my Github Actions container to AWS.

When I invoke my lambda, I experience an import error:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'axios'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        ...
    ]
}

My lambda folder structure is correct, and it was previously able to execute successfully. I double, triple, quadruple checked my package.json - axios is there. I even see node_modules/axios in the AWS Lambda Console. I can't reproduce the bug locally.

Turns out I needed to chmod -R 777 . before zipping and uploading the lambda code as part of my deployment pipeline.

I was previously chmod -R 744 . but that doesn't cut it.

This only became a problem when I included dependencies as part of node_modules .

If you know the exact chmod level necessary, please comment below.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM