Created
June 18, 2021 07:29
-
-
Save toricls/2e8d899888cfce85eac0e57361ba1fdd to your computer and use it in GitHub Desktop.
Step Functions example state machine - retrying by stoppedReason of ECS task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "1.0", | |
"Comment": "Run AWS Fargate task", | |
"TimeoutSeconds": 900, | |
"StartAt": "Run Fargate Task", | |
"States": { | |
"Run Fargate Task": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::ecs:runTask.sync", | |
"Parameters": { | |
"LaunchType": "FARGATE", | |
"Cluster": "<Cluster-ARN>", | |
"TaskDefinition": "<TaskDef-ARN>", | |
"Group.$": "$$.Execution.Name", | |
"NetworkConfiguration": { | |
"AwsvpcConfiguration": { | |
"Subnets": [ | |
"<Subnet-1>", | |
"<Subnet-2>", | |
"<Subnet-3>" | |
], | |
"AssignPublicIp": "ENABLED", | |
"SecurityGroups": [ | |
"<SecurityGroup-ID>" | |
] | |
} | |
}, | |
"Overrides": { | |
"ContainerOverrides": [ | |
{ | |
"Name": "<Container-Name>", | |
"Environment": [ | |
{ | |
"Name": "<Environment-Variable-Name-To-Override>", | |
"Value": "<Environment-Variable-Value-To-Override>" | |
} | |
] | |
} | |
] | |
} | |
}, | |
"End": true, | |
"Catch": [ | |
{ | |
"ErrorEquals": [ | |
"States.TaskFailed" | |
], | |
"Next": "Cause to Json" | |
} | |
] | |
}, | |
"Cause to Json": { | |
"Type": "Pass", | |
"Parameters": { | |
"Cause.$": "States.StringToJson($.Cause)" | |
}, | |
"Next": "Retry or Finish" | |
}, | |
"Retry or Finish": { | |
"Type": "Choice", | |
"Choices": [ | |
{ | |
"Variable": "$.Cause.StoppedReason", | |
"StringMatches": "ResourceInitializationError: *", | |
"Next": "Run Fargate Task" | |
} | |
], | |
"Default": "Fail" | |
}, | |
"Fail": { | |
"Type": "Fail" | |
} | |
} | |
} |
Note: On Fargate, the "ResourceInitializationError" error used in the example above only occurs on platform version 1.4.0 or later
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pros
Cons