0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

StepFunctionsでのエラー情報の保持と継続的な進行

Last updated at Posted at 2023-10-29

複数の処理でエラーがあっても、他の処理は進行を続ける方法

2つの処理の流れがある、次のフローについてです。

2つとも成功の例:
image.png

片方がエラーの例:
image.png
image.png

両方がエラーの例:
image.png

設計のプレビュー(両方がエラーの例)

エラーは Failステートで表現しています。
image.png

ポイント紹介

IsErrorをセットする PARA_A_SUCCESSからPARA_B_ERRORは、

{
  "IsError": "True"
}

のように書くのみです。(ResultPathを使用して・・・といった他のチェックは無し)
これらの載っている BASE_1 パラレルステートで、
  チェック入れる:ResultPath を使用して元の入力を出力に追加 - 省略可能
  Combine Original input with result
 $.BASE_1_Result
この組み合わせをしていくと、うまく保持されます。
BASE_GROUPはパラレル処理結果は配列でfalse trueの組み合わせだったりするので、1つのtrueにする、ようにして、結果を出力しています。

上記のをシーケンシャルに2つ繋げたケース

※名称を修正しています。
image.png

2つ繋げたケースのソースコード

{
  "Comment": "A description of my state machine",
  "StartAt": "BASE_1_GROUP",
  "States": {
    "BASE_1_GROUP": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "BASE_1",
          "States": {
            "BASE_1": {
              "Type": "Parallel",
              "Branches": [
                {
                  "StartAt": "BASE_1_PARA_A",
                  "States": {
                    "BASE_1_PARA_A": {
                      "Type": "Parallel",
                      "Branches": [
                        {
                          "StartAt": "BASE_1_PARA_A_JOB_1",
                          "States": {
                            "BASE_1_PARA_A_JOB_1": {
                              "Type": "Wait",
                              "Seconds": 5,
                              "Next": "BASE_1_PARA_A_JOB_2"
                            },
                            "BASE_1_PARA_A_JOB_2": {
                              "Type": "Pass",
                              "End": true
                            }
                          }
                        }
                      ],
                      "Next": "BASE_1_PARA_A_SUCCESS",
                      "Catch": [
                        {
                          "ErrorEquals": [
                            "States.ALL"
                          ],
                          "Next": "BASE_1_PARA_A_ERROR"
                        }
                      ]
                    },
                    "BASE_1_PARA_A_ERROR": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "True"
                      }
                    },
                    "BASE_1_PARA_A_SUCCESS": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "False"
                      }
                    }
                  }
                },
                {
                  "StartAt": "BASE_1_PARA_B",
                  "States": {
                    "BASE_1_PARA_B": {
                      "Type": "Parallel",
                      "Branches": [
                        {
                          "StartAt": "BASE_1_PARA_B_JOB_1",
                          "States": {
                            "BASE_1_PARA_B_JOB_1": {
                              "Type": "Pass",
                              "Next": "BASE_1_PARA_B_Fail"
                            },
                            "BASE_1_PARA_B_Fail": {
                              "Type": "Fail"
                            }
                          }
                        }
                      ],
                      "Catch": [
                        {
                          "ErrorEquals": [
                            "States.ALL"
                          ],
                          "Next": "BASE_1_PARA_B_ERROR"
                        }
                      ],
                      "Next": "BASE_1_PARA_B_SUCCESS"
                    },
                    "BASE_1_PARA_B_SUCCESS": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "False"
                      }
                    },
                    "BASE_1_PARA_B_ERROR": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "True"
                      }
                    }
                  }
                }
              ],
              "Next": "BASE_1_CHECK",
              "ResultPath": "$.BASE_1_Result"
            },
            "BASE_1_CHECK": {
              "Type": "Choice",
              "Choices": [
                {
                  "Or": [
                    {
                      "Variable": "$.BASE_1_Result[0].IsError",
                      "StringEquals": "True"
                    },
                    {
                      "Variable": "$.BASE_1_Result[1].IsError",
                      "StringEquals": "True"
                    }
                  ],
                  "Next": "BASE_1_FAILED"
                }
              ],
              "Default": "BASE_1_SUCCESS"
            },
            "BASE_1_FAILED": {
              "Type": "Pass",
              "Result": {
                "IsError": "True"
              },
              "End": true
            },
            "BASE_1_SUCCESS": {
              "Type": "Pass",
              "Result": {
                "IsError": "False"
              },
              "End": true
            }
          }
        }
      ],
      "Next": "BASE_2_GROUP",
      "ResultPath": "$.BASE_1_Result"
    },
    "BASE_2_GROUP": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "BASE_2",
          "States": {
            "BASE_2": {
              "Type": "Parallel",
              "Branches": [
                {
                  "StartAt": "BASE_2_PARA_A",
                  "States": {
                    "BASE_2_PARA_A": {
                      "Type": "Parallel",
                      "Branches": [
                        {
                          "StartAt": "BASE_2_PARA_A_JOB_1",
                          "States": {
                            "BASE_2_PARA_A_JOB_1": {
                              "Type": "Wait",
                              "Seconds": 5,
                              "Next": "BASE_2_PARA_A_JOB_2"
                            },
                            "BASE_2_PARA_A_JOB_2": {
                              "Type": "Pass",
                              "End": true
                            }
                          }
                        }
                      ],
                      "Next": "BASE_2_PARA_A_SUCCESS",
                      "Catch": [
                        {
                          "ErrorEquals": [
                            "States.ALL"
                          ],
                          "Next": "BASE_2_PARA_A_ERROR"
                        }
                      ]
                    },
                    "BASE_2_PARA_A_ERROR": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "True"
                      }
                    },
                    "BASE_2_PARA_A_SUCCESS": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "False"
                      }
                    }
                  }
                },
                {
                  "StartAt": "BASE_2_PARA_B",
                  "States": {
                    "BASE_2_PARA_B": {
                      "Type": "Parallel",
                      "Branches": [
                        {
                          "StartAt": "BASE_2_PARA_B_JOB_1",
                          "States": {
                            "BASE_2_PARA_B_JOB_1": {
                              "Type": "Pass",
                              "End": true
                            }
                          }
                        }
                      ],
                      "Catch": [
                        {
                          "ErrorEquals": [
                            "States.ALL"
                          ],
                          "Next": "BASE_2_PARA_B_ERROR"
                        }
                      ],
                      "Next": "BASE_2_PARA_B_SUCCESS"
                    },
                    "BASE_2_PARA_B_SUCCESS": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "False"
                      }
                    },
                    "BASE_2_PARA_B_ERROR": {
                      "Type": "Pass",
                      "End": true,
                      "Result": {
                        "IsError": "True"
                      }
                    }
                  }
                }
              ],
              "Next": "BASE_2_CHECK",
              "ResultPath": "$.BASE_2_Result"
            },
            "BASE_2_CHECK": {
              "Type": "Choice",
              "Choices": [
                {
                  "Or": [
                    {
                      "Variable": "$.BASE_2_Result[0].IsError",
                      "StringEquals": "True"
                    },
                    {
                      "Variable": "$.BASE_2_Result[1].IsError",
                      "StringEquals": "True"
                    }
                  ],
                  "Next": "BASE_2_FAILED"
                }
              ],
              "Default": "BASE_2_SUCCESS"
            },
            "BASE_2_FAILED": {
              "Type": "Pass",
              "Result": {
                "IsError": "True"
              },
              "End": true
            },
            "BASE_2_SUCCESS": {
              "Type": "Pass",
              "Result": {
                "IsError": "False"
              },
              "End": true
            }
          }
        }
      ],
      "Next": "BASE_3",
      "ResultPath": "$.BASE_2_Result"
    },
    "BASE_3": {
      "Type": "Pass",
      "Result": {
        "IsError": "False"
      },
      "ResultPath": "$.BASE_2_Result",
      "End": true
    }
  }
}
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?