title: AWS Steps Function: timed out Fargate task not automatically killed
body: <p>I have a <a href="https://docs.aws.amazon.com/step-functions/latest/dg/getting-started.html" rel="nofollow noreferrer">AWS Step Function</a> which is configured to run a <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html" rel="nofollow noreferrer">Fargate</a> 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 <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html" rel="nofollow noreferrer">TimeoutSeconds</a> parameter in the task definition:</p>
  <pre class="lang-yaml prettyprint-override"><code>StartAt: FargateWorker
  States:
    FargateWorker:
      Type: Task
      Resource: arn:aws:states:::ecs:runTask.waitForTaskToken
      InputPath: $
      ResultPath: $.workerResult
      OutputPath: $
      TimeoutSeconds: 3
      Parameters:
        Cluster: &quot;#{EcsCluster}&quot;
        TaskDefinition: &quot;#{EcsTaskDefinition}&quot;
        LaunchType: FARGATE
        EnableExecuteCommand: true
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets:
              - xxx
              - yyy
              - zzz
            AssignPublicIp: DISABLED
        Overrides:
          ContainerOverrides:
            - Name: container-${env:STACK_NAME}
              Environment:
                - Name: TASK_TOKEN
                  &quot;Value.$&quot;: $$.Task.Token
      Catch:
        - ErrorEquals: [&quot;States.ALL&quot;]
          Next: CatchAllFallback
      Next: Done
  </code></pre>
  <p>I can see the state machine correctly moves to the <code>CatchAllFallback</code> state after <code>TimeoutSeconds</code> 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?</p>