{
    "Comment": "DBダンプ取得ステートマシン",
    "StartAt": "params",
    "States": {
        "params": {
            "Comment": "パラメータ設定",
            "Type": "Pass",
            "Parameters": {
                "ecs": {
                    "LaunchType": "FARGATE",
                    "Cluster": "arn:aws:ecs:#{REGION_AP_NORTHEAST_1}:#{AWS_ACCOUNT_ID}:cluster/mbj-newdwh2021-#{ENV_NAME}-export-dbdump-ecs",
                    "TaskDefinition": "arn:aws:ecs:#{REGION_AP_NORTHEAST_1}:#{AWS_ACCOUNT_ID}:task-definition/mbj-newdwh2021-#{ENV_NAME}-task-export-dbdump",
                    "NetworkConfiguration": {
                        "AwsvpcConfiguration": {
                            "Subnets": [
                                "#{SUBNET_PRI_1A}",
                                "#{SUBNET_PRI_1D}"
                            ],
                            "SecurityGroups": [
                                "#{SG_ECS_ALL}",
                                "#{SG_EXPORT_DBDUMP}"
                            ],
                            "AssignPublicIp": "DISABLED"
                        }
                    },
                    "Overrides": {
                        "ContainerOverrides": [
                            {
                                "Name": "mbj-newdwh2021-#{ENV_NAME}-container-export-dbdump",
                                "Environment": [
                                    {
                                        "Name": "DB_SCHEMA",
                                        "Value.$": "$.db_schema"
                                    },
                                    {
                                        "Name": "DUMP_BACKUP_BUCKET",
                                        "Value.$": "$.dump_backup_bucket"
                                    }
                                ]
                            }
                        ]
                    }
                }
            },
            "ResultPath": "$.params",
            "Next": "exec-export-dbdump"
        },
        "exec-export-dbdump": {
            "Type": "Task",
            "Resource": "arn:aws:states:::ecs:runTask.sync",
            "Parameters": {
                "LaunchType.$": "$.params.ecs.LaunchType",
                "Cluster.$": "$.params.ecs.Cluster",
                "TaskDefinition.$": "$.params.ecs.TaskDefinition",
                "NetworkConfiguration.$": "$.params.ecs.NetworkConfiguration",
                "Overrides.$": "$.params.ecs.Overrides"
            },
            "ResultPath": "$.result",
            "Retry": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "BackoffRate": 2,
                    "IntervalSeconds": 3,
                    "MaxAttempts": 3
                }
            ],
            "Catch": [
                {
                    "ErrorEquals": [
                        "States.ALL"
                    ],
                    "Next": "ErrorEnd",
                    "ResultPath": "$.result"
                }
            ],
            "Next": "NormalEnd",
            "Comment": "データ登録処理"
        },
        "NormalEnd": {
            "Comment": "正常終了",
            "Type": "Succeed"
        },
        "ErrorEnd": {
            "Comment": "異常終了",
            "Type": "Fail",
            "Error": "StatesError",
            "Cause": "StepFunctions ErrorEnd"
        }
    }
}