Skip to content

Instantly share code, notes, and snippets.

@toricls
Created June 18, 2021 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toricls/2e8d899888cfce85eac0e57361ba1fdd to your computer and use it in GitHub Desktop.
Save toricls/2e8d899888cfce85eac0e57361ba1fdd to your computer and use it in GitHub Desktop.
Step Functions example state machine - retrying by stoppedReason of ECS task
{
"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"
}
}
}
@toricls
Copy link
Author

toricls commented Jun 18, 2021

This is the visualized version of the example state machine above :)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment