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回答
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
エキスパート
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ