{
  "Comment": "Validate Bulk Metadata Step Function",
  "StartAt": "AVScan",
  "States": {
    "AVScan": {
      "Type": "Task",
      "Resource": "${check_guardduty_scan_status_lambda_arn}",
      "Next": "ValidateSpreadsheet",
      "Retry": [
        {
          "ErrorEquals": [
            "NetworkException",
            "GraphQLException",
            "HTTPStatusError",
            "ReadTimeout",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 8,
          "Comment": "Retry 8 times with a backoff rate of 2"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        }
      ]
    },
    "ValidateSpreadsheet": {
      "Type": "Task",
      "Resource": "arn:aws:states:::ecs:runTask.waitForTaskToken",
      "TimeoutSeconds": 43200,
      "HeartbeatSeconds": 120,
      "Parameters": {
        "LaunchType": "FARGATE",
        "Cluster": "${fargate_cluster_arn}",
        "TaskDefinition": "${fargate_task_arn}",
        "NetworkConfiguration": {
          "AwsvpcConfiguration": {
            "Subnets": [
              "${subnet_id0}",
              "${subnet_id1}"
            ],
            "AssignPublicIp": "DISABLED"
          }
        },
        "Overrides": {
          "ContainerOverrides": [
            {
              "Name": "validate-spreadsheet",
              "Environment": [
                {
                  "Name": "TASK_TOKEN",
                  "Value.$": "$$.Task.Token"
                },
                {
                  "Name": "BUCKET",
                  "Value.$": "$.detail.bucket.name"
                },
                {
                  "Name": "KEY",
                  "Value.$": "$.detail.object.key"
                }
              ]
            }
          ]
        }
      },
      "Retry": [
        {
          "ErrorEquals": [
            "NetworkException",
            "States.TaskFailed"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 8,
          "Comment": "Retry 8 times with a backoff rate of 2"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "Catch all errors"
        }
      ],
      "Next": "IsValid",
      "ResultPath": "$.validation"
    },
    "IsValid": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.validation.is_valid",
          "BooleanEquals": false,
          "Next": "GenerateReport"
        }
      ],
      "Default": "GenerateJSON"
    },
    "GenerateReport": {
      "Type": "Task",
      "Resource": "${generate_report_lambda_arn}",
      "Next": "SuccessState",
      "Retry": [
        {
          "ErrorEquals": [
            "NetworkException",
            "GraphQLException",
            "HTTPStatusError",
            "ReadTimeout",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 8,
          "Comment": "Retry 8 times with a backoff rate of 2"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        }
      ]
    },
    "GenerateJSON": {
      "Type": "Task",
      "Resource": "${generate_json_lambda_arn}",
      "Next": "SuccessState",
      "Retry": [
        {
          "ErrorEquals": [
            "NetworkException",
            "GraphQLException",
            "HTTPStatusError",
            "ReadTimeout",
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 8,
          "Comment": "Retry 8 times with a backoff rate of 2"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.Runtime"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        },
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "HandleFailure",
          "ResultPath": "$.otherException",
          "Comment": "All other errors"
        }
      ]
    },
    "HandleFailure": {
      "Type": "Task",
      "Resource": "${handle_failure_lambda_arn}",
      "Next": "FailureState"
    },
    "SuccessState": {
      "Type": "Succeed"
    },
    "FailureState": {
      "Type": "Fail"
    }
  }
}
