{
    "Comment": "Podcast Assets Transcoding State Machine",
    "StartAt": "Acknowledge",
    "States": {
      "Acknowledge": {
        "Type": "Task",
        "Resource": "${acknowledge_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "AcknowledgeError"
          }
        ],
        "Next": "EncodingRoute"
      },
      "EncodingRoute": {
        "Type": "Task",
        "Resource": "${encoding_route_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "EncodingRouteError"
          }
        ],
        "Next": "ChoiceTranscoding"
      },
      "ChoiceTranscoding": {
        "Type": "Choice",
        "Choices": [
          {
            "Variable": "$.transcoding_type",
            "StringEquals": "audio",
            "Next": "AudioValidation"
          },
          {
            "Variable": "$.transcoding_type",
            "StringEquals": "image",
            "Next": "ImageValidation"
          }
        ],
        "Default": "UnknownTranscodingType"
      },
      "UnknownTranscodingType": {
        "Type": "Fail",
        "Cause": "Unknown transcoding type."
      },
      "AudioValidation": {
        "Type": "Task",
        "Resource": "${audio_validation_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["LoggedException"],
            "MaxAttempts": 3
          },
          {
            "ErrorEquals": ["InvalidAudioError"],
            "MaxAttempts": 0
          },
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["LoggedException"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["InvalidAudioError"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "AudioValidationError"
          }
        ],
        "Next": "AudioWaveform"
      },
      "AudioWaveform": {
        "Type": "Task",
        "Resource": "${audio_waveform_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["LoggedException"],
            "MaxAttempts": 3
          },
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["LoggedException"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["InvalidAudioError"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "AudioWaveformError"
          }
        ],
        "End": true
      },
      "ImageValidation": {
        "Type": "Task",
        "Resource": "${image_validation_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["InvalidImageError"],
            "MaxAttempts": 0
          },
          {
            "ErrorEquals": ["LoggedException"],
            "MaxAttempts": 3
          },
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["LoggedException"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["InvalidImageError"],
            "Next": "ErrorProcessed"
          },
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "ImageValidationError"
          }
        ],
        "Next": "ImageEncoding"
      },
      "ImageEncoding": {
        "Type": "Task",
        "Resource": "${image_encoding_lambda_arn}",
        "Retry": [
          {
            "ErrorEquals": ["States.ALL"],
            "IntervalSeconds": 1,
            "MaxAttempts": 3
          }
        ],
        "Catch": [
          {
            "ErrorEquals": ["States.ALL"],
            "ResultPath": "$.Error",
            "Next": "ImageEncodingError"
          }
        ],
        "End": true
      },
      "AcknowledgeError": {
        "Type": "Pass",
        "Result": "acknowledge",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "EncodingRouteError": {
        "Type": "Pass",
        "Result": "encoding_route",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "AudioValidationError": {
        "Type": "Pass",
        "Result": "audio-validation",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "AudioWaveformError": {
        "Type": "Pass",
        "Result": "audio-waveform",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "ImageValidationError": {
        "Type": "Pass",
        "Result": "images-validation",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "ImageEncodingError": {
        "Type": "Pass",
        "Result": "images-encoding",
        "ResultPath": "$.Function",
        "Next": "ErrorReporting"
      },
      "ErrorReporting": {
        "Type": "Task",
        "Resource": "${error_reporting_lambda_arn}",
        "Next": "ErrorProcessed"
      },
      "ErrorProcessed": {
        "Type": "Fail",
        "Cause": "The error was processed by lambda function"
      }
    }
  }
