drpexe
drpexe

Reputation: 461

What happens when I stop an execution in AWS Step Functions?

I was reading the API documentation an there's an action called StopExecution.

https://docs.aws.amazon.com/step-functions/latest/apireference/API_StopExecution.html

I was wondering what it does. Yes, of course, it stops the execution, but what if some task is running? Does it send a signal to stop the task like SWF does? Or just revoke the TaskToken (so the task cannot send the results back) and leave it running? Does the same happens if the task is a lambda function?

I was thinking about this because I have some long running tasks and could not find this behavior documented anywhere.

My guess: It just signals the execution as stopped and leave the task running. When the tasks calls SendTaskSuccess, it just receives an error like InvalidToken.

Upvotes: 16

Views: 10936

Answers (3)

evilGenious
evilGenious

Reputation: 917

The accepted answer goes way back but I just discovered that AWS now also stops the underlying task:

Task stopped at: 2024-04-24T01:23:32.972Z

The Task state in AWS Step Functions execution [execution arn ] which was managing this resource was aborted

So you should be able to click "Stop Execution" in the UI and that should automatically stop the task.

Hope this helps any future readers 👍

Upvotes: 0

user1331590
user1331590

Reputation: 41

In the case of Batch job, it does stop the step and the Job Terminate with exitCode 1 and the following reason: Status reason: The Task state in AWS Step Functions execution [arn:aws:states:us-west-2:12345678912:execution:JobStateMachine:00000-c583-2050-f8b1-9d36e05f4266] which was managing this resource was aborted

Upvotes: 4

drpexe
drpexe

Reputation: 461

I did the testing and it turns out that SFN does absolutely nothing to stop a running task. However, if you try to SendTaskHeartbeat on a stopped execution it will throw a TaskTimedOut error.

What I ended up doing was to verify the output of SendTaskHeartbeat, catch TaskTimedOut and proceed with the task cancellation on the worker side.

Note: The same TaskTimedOut error happens on SendTaskSuccess/SendTaskFailure.

Upvotes: 11

Related Questions