{
    "Comment": "Copy Bulk Session Asset Step Function",
    "StartAt": "SetupContext",
    "States": {
        "SetupContext": {
            "Type": "Pass",
            "Parameters": {
                "execution_arn.$": "$$.Execution.Id",
                "bulk_session_id.$": "$[0].bulk_session_id",
                "bulk_session_asset_file_id.$": "$[0].bulk_session_asset_file_id",
                "bulk_session_ingestion_id.$": "$[0].bulk_session_ingestion_id",
                "identity_uuid.$": "$[0].identity_uuid",
                "correlation_id.$": "$[0].correlation_id",
                "asset.$": "$[0].asset"
            },
            "Next": "BeginCopyAsset"
        },
        "BeginCopyAsset": {
            "Type": "Task",
            "Resource": "${begin_copy_asset_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "NetworkException",
                        "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"
                },
                {
                    "ErrorEquals": [
                        "AssetNotFound"
                    ],
                    "MaxAttempts": 0,
                    "Comment": "Don't retry"
                },
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 1,
                    "IntervalSeconds": 300,
                    "MaxAttempts": 1,
                    "Comment": "Retry once on any failure"
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "HandleCopyAssetFailure",
                    "ResultPath": "$.exception",
                    "Comment": "Error after retry"
                }
            ],
            "Next": "CopyAsset"
        },
        "CopyAsset": {
            "Type": "Task",
            "Resource": "${copy_asset_lambda_arn}",
            "Next": "PollAssetStatus",
            "Retry": [
                {
                    "ErrorEquals": [
                        "NetworkException",
                        "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"
                },
                {
                    "ErrorEquals": [
                        "AssetNotFound"
                    ],
                    "MaxAttempts": 0,
                    "Comment": "Don't retry"
                },
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 1,
                    "IntervalSeconds": 300,
                    "MaxAttempts": 1,
                    "Comment": "Retry once on any failure"
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "HandleCopyAssetFailure",
                    "ResultPath": "$.exception",
                    "Comment": "Error after retry"
                }
            ]
        },
        "PollAssetStatus": {
            "Type": "Task",
            "Resource": "${poll_asset_status_lambda_arn}",
            "Retry": [
                {
                    "ErrorEquals": [
                        "RetryException"
                    ],
                    "IntervalSeconds": 60,
                    "MaxAttempts": 120,
                    "BackoffRate": 1
                },
                {
                    "ErrorEquals": [
                        "NetworkException",
                        "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"
                },
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 1,
                    "IntervalSeconds": 300,
                    "MaxAttempts": 1,
                    "Comment": "Retry once on any failure"
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "HandleCopyAssetFailure",
                    "ResultPath": "$.exception",
                    "Comment": "Error after retry"
                }
            ],
            "Next": "HandleCopyAssetSuccess"
        },
        "HandleCopyAssetSuccess": {
            "Type": "Task",
            "Resource": "${handle_asset_copy_success_lambda_arn}",
            "Next": "Success",
            "Retry": [
                {
                    "ErrorEquals": [
                        "NetworkException",
                        "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"
                },
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 1,
                    "IntervalSeconds": 300,
                    "MaxAttempts": 1,
                    "Comment": "Retry once on any failure"
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "Failure",
                    "ResultPath": "$.exception",
                    "Comment": "Error after retry"
                }
            ]
        },
        "Success": {
            "Type": "Succeed"
        },
        "HandleCopyAssetFailure": {
            "Type": "Task",
            "Resource": "${handle_asset_copy_failure_lambda_arn}",
            "Next": "Failure",
            "Retry": [
                {
                    "ErrorEquals": [
                        "NetworkException",
                        "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"
                },
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 1,
                    "IntervalSeconds": 300,
                    "MaxAttempts": 1,
                    "Comment": "Retry once on any failure"
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "Failure",
                    "ResultPath": "$.exception",
                    "Comment": "Error after retry"
                }
            ]
        },
        "Failure": {
            "Type": "Fail",
            "ErrorPath": "$.exception.Error",
            "CausePath": "States.Format('Error: {}, Cause: {}', $.exception.Error, $.exception.Cause)"
        }
    }
}
