admin管理员组文章数量:1026989
I tried to deploy a simple function using AWS Lambda. However, I got this error even though I set the handler correctly. P/s: I did not use the serverless.yml nor CLI. I deployed it using AWS Lambda interface.
Lambda Handler: functions/fetchNest/handler.fetch
Error:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'handler'",
"Require stack:",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
" at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
" at async start (file:///var/runtime/index.mjs:1137:23)",
" at async file:///var/runtime/index.mjs:1143:1"
]
handler.js
module.exports.fetch = async event => {
// Get SSM creds.
folder structure
I tried to deploy a simple function using AWS Lambda. However, I got this error even though I set the handler correctly. P/s: I did not use the serverless.yml nor CLI. I deployed it using AWS Lambda interface.
Lambda Handler: functions/fetchNest/handler.fetch
Error:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'handler'",
"Require stack:",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
" at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
" at async start (file:///var/runtime/index.mjs:1137:23)",
" at async file:///var/runtime/index.mjs:1143:1"
]
handler.js
module.exports.fetch = async event => {
// Get SSM creds.
folder structure
Share Improve this question edited Oct 20, 2022 at 21:32 John Rotenstein 271k28 gold badges448 silver badges532 bronze badges asked Oct 20, 2022 at 20:53 Lucas.PhelinyLucas.Pheliny 1251 gold badge2 silver badges9 bronze badges 2- Start with the sample code provided by Amazon and build from there. I bet your handler should be something much simpler like "handler" instead of what you're using – Jader Dias Commented Oct 20, 2022 at 21:06
- It should be judging by the code I provide which it didn't work. Not that passing the code from Amazon would make it work. – Lucas.Pheliny Commented Oct 20, 2022 at 21:17
1 Answer
Reset to default 2Don't use Compress FileName
in MacOS, else you'll end up zipping your files with chaos. Use mand zip
instead. For example:
zip testFile.zip index.js node_modules utils
This will create the zip file contains all your required sub files and folders. After that you can config your Handler in Lambda like this
testFile/index.hander
I tried to deploy a simple function using AWS Lambda. However, I got this error even though I set the handler correctly. P/s: I did not use the serverless.yml nor CLI. I deployed it using AWS Lambda interface.
Lambda Handler: functions/fetchNest/handler.fetch
Error:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'handler'",
"Require stack:",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
" at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
" at async start (file:///var/runtime/index.mjs:1137:23)",
" at async file:///var/runtime/index.mjs:1143:1"
]
handler.js
module.exports.fetch = async event => {
// Get SSM creds.
folder structure
I tried to deploy a simple function using AWS Lambda. However, I got this error even though I set the handler correctly. P/s: I did not use the serverless.yml nor CLI. I deployed it using AWS Lambda interface.
Lambda Handler: functions/fetchNest/handler.fetch
Error:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'handler'",
"Require stack:",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:951:17)",
" at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)",
" at async start (file:///var/runtime/index.mjs:1137:23)",
" at async file:///var/runtime/index.mjs:1143:1"
]
handler.js
module.exports.fetch = async event => {
// Get SSM creds.
folder structure
Share Improve this question edited Oct 20, 2022 at 21:32 John Rotenstein 271k28 gold badges448 silver badges532 bronze badges asked Oct 20, 2022 at 20:53 Lucas.PhelinyLucas.Pheliny 1251 gold badge2 silver badges9 bronze badges 2- Start with the sample code provided by Amazon and build from there. I bet your handler should be something much simpler like "handler" instead of what you're using – Jader Dias Commented Oct 20, 2022 at 21:06
- It should be judging by the code I provide which it didn't work. Not that passing the code from Amazon would make it work. – Lucas.Pheliny Commented Oct 20, 2022 at 21:17
1 Answer
Reset to default 2Don't use Compress FileName
in MacOS, else you'll end up zipping your files with chaos. Use mand zip
instead. For example:
zip testFile.zip index.js node_modules utils
This will create the zip file contains all your required sub files and folders. After that you can config your Handler in Lambda like this
testFile/index.hander
版权声明:本文标题:javascript - "Error: Cannot find module 'handler'nRequire stack:n- varruntimeindex.mjs" - Stac 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745675814a2162733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论