Lambda function call returns 500 error

0

I fear this is a rather basic question, but, I've been stuck on it for too long now. I've set up a Lambda Function, when I run the initial (hello world) test it all works fine. But, as soon as I replace the code with a zip from an S3 bucket, it fails. The log shows this: Error: Cannot find module 'index' and more pertinently: "Require stack:", "- /var/runtime/index.mjs",

index.mjs is what the hello world runs from, but, in my zip this is index.js - the runtime configuration seems to be correct looking for index.handler... but I can't see anywhere where I can change this. Can anyone point me in the right direction?

已提問 3 個月前檢視次數 208 次
1 個回答
2
已接受的答案

Check that your zip file has the index.js file at the root of the zip file (it's easy to accidentally end up with it in a subdirectory). You want to ensure you are just zipping up the files and not the directory - e.g. zip lambda.zip index.js

AWS
Gillian
已回答 3 個月前
profile picture
專家
已審閱 2 個月前
  • Thanks for the response!

    When I read this I was 'oh duh' because I'd completely done as you'd said (zipping the directory not the files.)

    Sadly, correctly zipping the files, hasn't resolved the issue, same error...

    This is the error in its entirety: { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'index'\nRequire stack:\n- /var/runtime/index.mjs", "stack": [ "Runtime.ImportModuleError: Error: Cannot find module 'index'", "Require stack:", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1" ] }

    To my (admittedly amateur) eye, it looks like something is still pointing at the old 'hello-world' set-up, but... it's only a guess.

  • CharlieM - Can you see the code source on the console once you have uploaded? If so you should see a folder with your lambda's name and then index.js immediately below it. If you can't see the source because you have dependencies that are making it too big, try to just zip up the index.js on its own and check the structure looks correct.

  • Thank you! In fact your initial advice was correct, and my initial fix was correct. What I hadn't realised was that when I updated the zip, I had to recopy it into the Lambda function. Now working as expected.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南