{
  "Comment": "Bulk Upload NR Sound Recordings.",
  "StartAt": "AvScan",
  "States": {
    "AvScan": {
      "Type": "Task",
      "Resource": "${av_scan_lambda_arn}",
      "ResultPath": "$.avScanResult",
      "Next": "IsThereVirus",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 3,
          "Comment": "Retry on timeout"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "GenerateReport",
          "ResultPath": "$.otherException",
          "Comment": "Error after retry"
        }
      ]
    },
    "IsThereVirus": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.avScanResult.has_virus",
          "BooleanEquals": true,
          "Next": "GenerateReport"
        }
      ],
      "Default": "ValidateAndSplitFile"
    },
    "ValidateAndSplitFile": {
      "Type": "Task",
      "Resource": "${validate_lambda_arn}",
      "Next": "ValidationSuccess",
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "RetryException",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 2,
          "Comment": "Retry on selected errors"
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Comment": "all other errors",
          "Next": "GenerateReport",
          "ResultPath": "$.otherException"
        }
      ]
    },
    "ValidationSuccess": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.validRows",
          "IsPresent": true,
          "Next": "ProcessRows"
        }
      ],
      "Default": "GenerateReport"
    },
    "ProcessRows": {
      "Type": "Map",
      "ItemsPath": "$.validRows",
      "MaxConcurrency": 10,
      "Iterator": {
        "StartAt": "AddNRContribution",
        "States": {
          "AddNRContribution": {
            "Type": "Task",
            "Resource": "${contributor_lambda_arn}",
            "End": true,
            "Retry": [
              {
                "ErrorEquals": [
                  "States.Timeout",
                  "Lambda.ServiceException",
                  "Lambda.AWSLambdaException",
                  "Lambda.SdkClientException",
                  "Lambda.TooManyRequestsException"
                ],
                "BackoffRate": 2,
                "IntervalSeconds": 60,
                "MaxAttempts": 2,
                "Comment": "Retry on timeout"
              }
            ]
          }
        }
      },
      "Next": "GenerateReport",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Comment": "all errors",
          "Next": "GenerateReport",
          "ResultPath": "$.otherException"
        }
      ]
    },
    "GenerateReport": {
      "Type": "Task",
      "Resource": "${report_lambda_arn}",
      "End": true,
      "Retry": [
        {
          "ErrorEquals": [
            "States.Timeout",
            "Lambda.ServiceException",
            "Lambda.AWSLambdaException",
            "Lambda.SdkClientException",
            "Lambda.TooManyRequestsException"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 60,
          "MaxAttempts": 2,
          "Comment": "Retry on timeout"
        }
      ]
    }
  }
}
