{
    "Comment": "Refresh QA DynamoDB table with Prod Snapshot, and apply QA-Specific Configurations",
    "StartAt": "NotifyStart",
    "States": {
        "NotifyStart": {
            "Type": "Task",
            "Resource": "arn:aws:states:::sns:publish",
            "Parameters": {
                "TopicArn": "${sns_notification_topic_arn}",
                "Subject": "⛲ 🚀 Starting prod->qa pp_identity DynamoDB Refresh",
                "Message.$": "States.Format('Execution Id: {}', $$.Execution.Id)"
            },
            "Next": "DynamodbStartRecoveryJob",
            "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 1,
                "MaxAttempts": 2,
                "BackoffRate": 2.0
            }],
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "DynamodbStartRecoveryJob"
            }]
        },
        "DynamodbStartRecoveryJob": {
            "Type": "Task",
            "Resource": "${lambda_start_refresh_arn}",
            "TimeoutSeconds": 900,
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.Timeout",
                        "Lambda.ServiceException",
                        "Lambda.AWSLambdaException",
                        "Lambda.SdkClientException",
                        "Lambda.TooManyRequestsException"
                    ],
                    "IntervalSeconds": 60,
                    "MaxAttempts": 5,
                    "BackoffRate": 3
                }
            ],
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "NotifyFail"
            }],
            "Next": "DynamodbPostRestore"
        },
        "DynamodbPostRestore": {
            "Type": "Task",
            "Resource": "${lambda_post_restore_arn}",
            "TimeoutSeconds": 900,
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.Timeout",
                        "Lambda.ServiceException",
                        "Lambda.AWSLambdaException",
                        "Lambda.SdkClientException",
                        "Lambda.TooManyRequestsException"
                    ],
                    "IntervalSeconds": 60,
                    "MaxAttempts": 5,
                    "BackoffRate": 3
                }
            ],
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "NotifyFail"
            }],
            "Next": "RunPDPBackfillRefresh"
        },
        "RunPDPBackfillRefresh": {
            "Type": "Task",
            "Resource": "arn:aws:states:::ecs:runTask.sync",
            "Parameters": {
                "LaunchType": "FARGATE",
                "Cluster": "${pdp_backfill_cluster_arn}",
                "TaskDefinition": "${pdp_backfill_task_definition_arn}",
                "NetworkConfiguration": {
                    "AwsvpcConfiguration": {
                        "Subnets": ${pdp_backfill_private_subnets},
                        "SecurityGroups": ["${pdp_backfill_task_security_group}"],
                        "AssignPublicIp": "DISABLED"
                    }
                },
                "Overrides": {
                    "ContainerOverrides": [
                        {
                            "Name": "${pdp_backfill_container_name}",
                            "Command": [
                                "backfill",
                                "process",
                                "--bucket-name",
                                "${backfill_bucket}",
                                "--manifest-file",
                                "${manifest_file_key}"
                            ]
                        }
                    ]
                }
            },
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "NotifyFail"
            }],
            "Next": "NotifySuccess"
        },
        "NotifySuccess": {
            "Type": "Task",
            "Resource": "arn:aws:states:::sns:publish",
            "Parameters": {
                "TopicArn": "${sns_notification_topic_arn}",
                "Subject": "⛲ 🥳 Successfully finished prod->qa pp_identity DynamoDB Refresh",
                "Message.$": "States.Format('Execution Id: {}', $$.Execution.Id)"
            },
            "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 1,
                "MaxAttempts": 2,
                "BackoffRate": 2.0
            }],
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "SuccessState"
            }],
            "Next": "SuccessState"
        },
        "NotifyFail": {
            "Type": "Task",
            "Resource": "arn:aws:states:::sns:publish",
            "Parameters": {
                "TopicArn": "${sns_notification_topic_arn}",
                "Subject": "⛲ 😵 ❌ 😵 FAILED prod->qa pp_identity DynamoDB Refresh",
                "Message.$": "$"
            },
            "Retry": [{
                "ErrorEquals": ["States.Timeout"],
                "IntervalSeconds": 1,
                "MaxAttempts": 2,
                "BackoffRate": 2.0
            }],
            "Catch": [{
                "ErrorEquals": ["States.ALL"],
                "Next": "FailState"
            }],
            "Next": "FailState"
        },
        "FailState": {
            "Type": "Fail"
        },
        "SuccessState": {
            "Type": "Succeed"
        }
    }
}
