From e641116ce4744015187330c9aecffcfb498a1584 Mon Sep 17 00:00:00 2001 From: Suleman Sohail <108665301+suleman-sohail@users.noreply.github.com> Date: Thu, 24 Aug 2023 20:04:31 +0500 Subject: [PATCH] Stopped Executions before deleting step functions state machines (#1053) * Added Deletion protection disable feature in cognito user-pool * Minor Changes * nit * spaces * spaces 2 * stopping executions * Stopped executiins * nit * Formatted --------- Co-authored-by: Suleman Sohail Co-authored-by: Philipp Trulson --- resources/sfn-statemachines.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/resources/sfn-statemachines.go b/resources/sfn-statemachines.go index e0748f7a..5edcd9a6 100644 --- a/resources/sfn-statemachines.go +++ b/resources/sfn-statemachines.go @@ -47,6 +47,27 @@ func ListSFNStateMachines(sess *session.Session) ([]Resource, error) { } func (f *SFNStateMachine) Remove() error { + params := &sfn.ListExecutionsInput{ + StateMachineArn: f.ARN, + } + + for { + executions, execError := f.svc.ListExecutions(params) + if execError != nil { + break + } + for _, execs := range executions.Executions { + + f.svc.StopExecution(&sfn.StopExecutionInput{ + ExecutionArn: execs.ExecutionArn, + }) + } + + if executions.NextToken == nil { + break + } + params.NextToken = executions.NextToken + } _, err := f.svc.DeleteStateMachine(&sfn.DeleteStateMachineInput{ StateMachineArn: f.ARN,