Lambda function call returns 500 error


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?

demandé il y a 3 mois204 vues
1 réponse
Réponse acceptée

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 index.js

répondu il y a 3 mois
profile picture
vérifié il y a 2 mois
  • 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.

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions