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달 전220회 조회
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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠