LoginSignup
0

More than 5 years have passed since last update.

Step Functions で パラレル実行するジョブごとにリトライ

Posted at

ググってもあまり情報でなかったのでやってみました。

ParallelのBranchのStateごとにretry書くことはできます。
マニュアルだとTypeがTaskかParallelにだけRetryが書けるとかいてあり分かりづらいですが、Parallelの中のTaskかParallelのTypeであればretryが書けます。言葉ではわかりずらいので以下のように失敗するLambda関数を一つ用意して以下をコピペして実行する(ベースはParallelのブループリントです)

{
  "Comment": "An example of the Amazon States Language using a parallel state to execute two branches at the same time.",
  "StartAt": "Parallel",
  "States": {
    "Parallel": {
      "Type": "Parallel",
      "Next": "Final State",
      "Branches": [
        {
          "StartAt": "Wait 20s",
          "States": {
            "Wait 20s": {
              "Type": "Task",
              "End": true,
              "Resource": "arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:test-lambda",
              "ResultPath": "$.chkcount",
              "Retry": [{
                "ErrorEquals": ["States.ALL"],
                "IntervalSeconds": 5,
                "MaxAttempts": 5,
                "BackoffRate": 2.0
               }]
            }
          }
        },
        {
          "StartAt": "Pass",
          "States": {
            "Pass": {
              "Type": "Pass",
              "Next": "Wait 10s"
            },
            "Wait 10s": {
              "Type": "Wait",
              "Seconds": 10,
              "End": true

            }
          }
        }

      ]
    },

    "Final State": {
      "Type": "Pass",
      "End": true
    }
  }
}

結果はこのような形でFailしているのがわかります。

スクリーンショット 0030-06-15 22.02.39.png

実行の履歴を見るとLambdaが6回Failしているのがわかります。つまり5回リトライされ6回目のFailでParallelStateFailになりパラレル処理全体のFailになったことがわかります

スクリーンショット 0030-06-15 22.02.51.png

スクリーンショット 0030-06-15 22.03.04.png

スクリーンショット 0030-06-15 22.03.11.png

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