Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDK Step Functions - How to create a loop

I'm trying to migrate a Step function that I created with the AWS interface and I encountered an issue with reproducing the following behavior:

Based on a condition, I want my task 2 to either execute task 3 and come back to the task 1 or to end the step function. My issue is the red path on the image enter image description here Here is the code I have for now:

sfn.Chain.start(OtherTaskWeDoNotCare)
  .next(task1)
  .next(
    new sfn.Choice(this, "task2").when(
      sfn.Condition.booleanEquals("$.isFinished", false),
      task3.next(task1) // This is not working
    )
  );

Hope someone can help me! Thanks in advance! 🙂

like image 593
Owl Avatar asked Jun 15 '26 14:06

Owl


1 Answers

I finally found how to do! 😅 Here is the code:

sfn.Chain.start(OtherTaskWeDoNotCareHere)
  .next(task1)
  .next(
    new sfn.Choice(this, "task2")
    .when(
      sfn.Condition.booleanEquals("$.isFinished", false),
      task3.next(task1)
    )
    .otherwise(new sfn.Succeed(this, "Done"))
  );
like image 191
Owl Avatar answered Jun 17 '26 04:06

Owl