I have a AWS Step Function which is configured to run a Fargate task, wait for completion and do some other work. The Fargate task is a long running process which can potentially get stuck during execution. To avoid this, I have configured a TimeoutSeconds parameter in the task definition:
StartAt: FargateWorker
States:
FargateWorker:
Type: Task
Resource: arn:aws:states:::ecs:runTask.waitForTaskToken
InputPath: $
ResultPath: $.workerResult
OutputPath: $
TimeoutSeconds: 3
Parameters:
Cluster: "#{EcsCluster}"
TaskDefinition: "#{EcsTaskDefinition}"
LaunchType: FARGATE
EnableExecuteCommand: true
NetworkConfiguration:
AwsvpcConfiguration:
Subnets:
- xxx
- yyy
- zzz
AssignPublicIp: DISABLED
Overrides:
ContainerOverrides:
- Name: container-${env:STACK_NAME}
Environment:
- Name: TASK_TOKEN
"Value.$": $$.Task.Token
Catch:
- ErrorEquals: ["States.ALL"]
Next: CatchAllFallback
Next: Done
I can see the state machine correctly moves to the CatchAllFallback state after TimeoutSeconds are passed, but the problem is that the Fargate container is still running, the state machine doesn't kill it. I need the container to be killed when the timeout triggers, so I don't end having a lot of zombie containers running until manual intervention. Is this something that can be addressed automatically by AWS in some way? Or any other solution?