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?

posta 3 mesi fa200 visualizzazioni
1 Risposta
2
Risposta accettata

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
con risposta 3 mesi fa
profile picture
ESPERTO
verificato 2 mesi fa
  • 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.

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande