Handle and return errors in lambda hapening on the init phase

0

Hi team,

I used this answer to exit my lambda when an error occur in Redis connect (Thank you @Indranil Banerjee AWS for your answer)

https://repost.aws/questions/QURgqZS0xaQcmfI0PkfT-4QA/handle-errors-in-lambda-hapening-on-the-init-phase

as my code ins in node js/javaScript not python I used process.exit() instead of sys.exit()

but my lambda still fails with a generated error and I can't return back my error response :

return {
    statusCode:"500",
    headers: {
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*",
    },
    body: JSON.stringify(MyresponseErrorObject),
  };

Enter image description here

if I do my return

return {
    statusCode:"500",
    headers: {
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*",
    },
    body: JSON.stringify(MyresponseErrorObject),
  };

after process.exit() it will be unreachable code.

is process.exit() the right way to exit lambda function in nodeJs (like sys.exit() in python) ?

my lambda still fails as shown in the screenshot above(this is a simulated error I made a mistake on the Redis URL so I can simulate the error and handle it properly outside the event handler code)

appreciate your help on this.

Thank you!

1 Antwort
0

Can you please take a look at "Designating a function handler as an ES module" section in https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html

Also take a look at this blog https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/

profile pictureAWS
EXPERTE
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen