【AWS】 Step Functions で複雑な処理を分割統治

Step Functions っちゃなんじゃ? => これです。

{
  "TimeoutSeconds": 1200,
  "StartAt": "Launch_Instance",
  "States": {
    "Launch_Instance": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-northeast-1:xxxxxxxxx:function:dev-step1",
      "Next": "Wait_For_A_While",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "On_Failure"
        }
      ],
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "MaxAttempts": 0
        }
      ]
    },
    "Wait_For_A_While": {
      "Type": "Wait",
      "Seconds": 10,
      "Next": "Check_Instance_Status"
    },
    "Check_Instance_Status": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-northeast-1:xxxxxxxxx:function:dev-step2",
      "Next": "Instance_Launched?",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "On_Failure"
        }
      ],
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "MaxAttempts": 0
        }
      ]
    },
    "Instance_Launched?": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.should_wait",
          "BooleanEquals": true,
          "Next": "Wait_For_A_While"
        }
      ],
      "Default": "On_Success"
    },
    "On_Success": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-northeast-1:xxxxxxxxx:function:dev-step3",
      "End": true,
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "On_Failure"
        }
      ],
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "MaxAttempts": 0
        }
      ]
    },
    "On_Failure": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:ap-northeast-1:xxxxxxxxx:function:dev-step4",
      "Next": "Failure",
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "MaxAttempts": 0
        }
      ]
    },
    "Failure": {
      "Type": "Fail"
    }
  }
}

あとは、それぞれのLambda関数を適宜実装してけば、 アホが書いてもLambda関数がカオスになるのを防げるってわけやで、奥さん。