Unable to invoke Lambda function

0

I have encountered an issue when invoking my lambda function. Tried different methods to test the function (CLI, uploading the zip file directly to Lambda ), however none of them worked. After looking into the function log, the error seems to occur from an import that failed to execute. The lambda function is also attached (node 16.x). index.js

The following is a detail of the function log: Function Logs 2023-06-25T19:06:43.696Z undefined ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'nanoid'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'nanoid'","Require stack:","- /var/task/index.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:997:17)"," at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)"," at async start (file:///var/runtime/index.mjs:1195:23)"," at async file:///var/runtime/index.mjs:1201:1"]}

3 回答
1

You can check resolution mentioned in similar post.

https://repost.aws/knowledge-center/lambda-import-module-error-nodejs

已回答 1 年前
  • So in this case, do I include the nanoid in the node_modules then deploy the zipped file ?

0

Does your Lambda code contains a node_modules with the library installed?

profile picture
专家
已回答 1 年前
0

It looks like you are referencing a module 'nanoid' that is not available by default and that you have not included in your Lambda zip file. This should help you install module and include it in the zip file. https://stackoverflow.com/questions/34437900/how-to-load-npm-modules-in-aws-lambda

profile pictureAWS
专家
iBehr
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则