LoginSignup
0
1

More than 1 year has passed since last update.

Lambdaの意外な罠?勝手にリトライされる問題に遭遇

Posted at

AWS Lambdaの関数でタイムアウトエラーが発生し、意図しないリトライが行われる問題に遭遇しました。
CloudWatchで確認してみると、関数が3回実行されていました。

リトライするような設定は特にしていなかったので、この現象は「クラウド破産」という文脈でちょっと怖い事態。

調べる

調べてみると、以下が見つかりました。

Lambda manages the function's asynchronous event queue and attempts to retry on errors. If the function returns an error, Lambda attempts to run it two more times, with a one-minute wait between the first two attempts, and two minutes between the second and third attempts. Function errors include errors returned by the function's code and errors returned by the function's runtime, such as timeouts.

要するに、
Lambdaは関数の非同期イベントキューを管理し、エラーが発生した場合にリトライを試みます。
ここで関数がエラーを返すと、1回目と2回目の試行の間に1分間、2回目と3回目の試行の間に2分間待機して、2回追加で実行を試みます
この関数エラーには、関数のコード自体から返されるエラーと、タイムアウトなどのランタイムから返されるエラーが含まれます。

つまり、初回と併せて、3回実行されることになります。

非同期イベント?

この非同期イベントには

  • Amazon Simple Storage Service (Amazon S3)
  • Amazon Simple Notification Service (Amazon SNS)
  • AWS EventBridge

などがあります。
今回は、まさしくこのEvent BridgeをトリガーにしてLambdaを実行していました。

結論

「非同期イベントでLambdaを実行する場合、明示的に設定していなくても自動でリトライされる」

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1