AWS Step Function sfn.ListExecutions not showing executions

204 Views Asked by At

I'm trying to list and stop all executions of a state machine. I'm using the following code to list and stop execution.

func stopAllExecutions(sfnSvc *sfn.SFN, stateMachineArn string) error {
    var nextToken *string
    // Since ListExecutionsInput only supports up to 1000 results per query, create loop to delete all executions
    for {
        executionsInput := &sfn.ListExecutionsInput{
            StateMachineArn:    aws.String(stateMachineArn),
            MaxResults:         aws.Int64(1000),
            NextToken:          nextToken,
            StatusFilter:       aws.String("RUNNING"),
        }
        executions, err := sfnSvc.ListExecutions(executionsInput)
        if err != nil {return err}
        for _, execution := range executions.Executions {
            if *execution.Status == "RUNNING" {
                _, err := sfnSvc.StopExecution(&sfn.StopExecutionInput{
                    ExecutionArn: execution.ExecutionArn,
                })
                if err != nil {
                    return err
                }
            }
        }

        // If NextToken is not set, there are no more results to retrieve
        if executions.NextToken == nil {
            break
        }
        nextToken = executions.NextToken
    }
    return nil
}

It will list executions, say they are deleted. If I run it again immediately, then it would should there's no execution. The AWS console shows there are no executions either. But if I run the aws cli command: aws stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN --status-filter RUNNING --output text, it will show I still have thousands of execution in the RUNNING state.

Then the strangest part is if I wait for a while (>30 mins), then my golang command will be able to see the executions again and "terminate" then, while it just behaves like before and not actually deleting them (in terms of what the aws cli command can see)

Any idea why this is the case?

1

There are 1 best solutions below

0
On

Looks like it's due to this line: *execution.Status == "RUNNING" that the execution status should be a pointer (type aws.String) and not a string. This line compares it against a normal string which caused the function never to actually stop the executions. However, it's still a mystery why the console did not show the executions after the operation...