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 Answers
1

You can check resolution mentioned in similar post.

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

answered 10 months ago
  • 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
EXPERT
answered 10 months ago
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
EXPERT
iBehr
answered 10 months ago
  • I have double checked my file directory and nanoid is imported

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions