Creating a loop in CDK Step Functions: A step-by-step guide

I am currently in the process of migrating a Step function that was initially created using the AWS interface. However, I have run into an issue while trying to replicate a specific behavior:

Depending on a certain condition, I need task 2 to either execute task 3 and return to task 1 or terminate the step function altogether. The problem lies with the red path shown in the image https://i.sstatic.net/A1vJv.png Here is the snippet of code I am working with at the moment:

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

I would appreciate any assistance from someone who may be able to help me resolve this issue! Thank you in advance! 🙂

Answer â„–1

After some trial and error, I have finally cracked the code! 😅 Check out the solution below:

sfn.Chain.start(AnotherTaskNotRelevant)
  .next(task1)
  .next(
    new sfn.Choice(this, "task2")
    .when(
      sfn.Condition.booleanEquals("$.isFinished", false),
      task3.next(task1)
    )
    .otherwise(new sfn.Succeed(this, "Done"))
  );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The usage of document is invalid in this context (Typescript)

Whenever I attempt to utilize TypeScript, the error message "ReferenceError: document is not defined" keeps popping up while using document.getElementByID();. Can someone please advise on how to resolve this issue? ...

Tips for Successfully Transmitting Information via Mat-Dialog

Having trouble passing data from a dialog back to the parent component. Specifically, I'm struggling with updating the value of an array in the `afterClosed` function. I've tried using `patchValue` and `setValue`, but it doesn't seem to be w ...

Enhancing current interfaces

I'm exploring Koa and the module system in Node.js. Although I'm not asking about a specific koa question, all the code I'm working with involves using koa. In Koa, every request is defined by the Request interface: declare module "koa" { ...

Defining TypeScript class events by extending EventEmitter

I have a class that extends EventEmitter and is capable of emitting the event hello. How can I properly declare the on method with a specific event name and listener signature? class MyClass extends events.EventEmitter { emitHello(name: string): void ...

Is it feasible to alter the file name while utilizing express-fileUpload library?

Is there a way to modify the file name of an uploaded file on the server side? app.post(URL, (req, res) => { let fileName = req.files.file.name; req.fileUpload; res.statusCode = HTTP_OK; res.send("Good Job") }) The settings I have in uploadF ...

Best practices for creating a versatile modal component

I have come across a few examples, but they all appear to be contradictory or intended for older versions of ng-bootstrap. What is the correct method for creating a basic modal that can be stored in a shared directory and then used for multiple modals on ...

Unshifting values in a JavaScript array only if they exist in another array

I have two arrays of objects - one containing selected data and the other containing general data that needs to be displayed General data for display const arr = [ { id: "1", name: "Skoda - Auto" }, { id: "2" ...

Customize Typing for Properties in Subclasses of Lit-Element Using TypeScript

When extending a lit-element Class to add more specific typing, should the @property decorator be overridden or just the type and initializer? For example, consider the following code: interface AB { a: number, b: string, } @customElement('my- ...

Exploring the possibilities of TypeScript/angularJS in HTTP GET requests

I am a beginner in typescript and angular.js, and I am facing difficulties with an http get request. I rely on DefinitelyTyped for angular's type definitions. This is what my controller code looks like: module game.Controller { 'use strict& ...

Exploring the Implementation of Validation Pipe in class-validator

I am currently exploring how to effectively utilize my validation pipe in combination with class-validator on an API call. My DTO is decorated with class-validator decorators and is performing as anticipated. However, I am interested in utilizing the &apo ...

Node.js does not allow the extension of the Promise object due to the absence of a base constructor with the required number of type

I'm trying to enhance the Promise object using this code snippet: class MyPromise extends Promise { constructor(executor) { super((resolve, reject) => { return executor(resolve, reject); }); } } But I keep encou ...

What is the method for dynamically assigning a name to ngModel?

I have the following code snippet: vmarray[]={'Code','Name','Place','City'} export class VMDetail { lstrData1:string; lstrData2:string; lstrData3:string; lstrData4:string; lstrData5:string; ...

I am puzzled as to why my function's return type transforms into a promise when I interact with the cell.value or use console.log

Recently, I embarked on the journey of coding a validation process for my Excel Sheet. To keep the code concise, I implemented it in a straightforward manner. Here is a snippet of my source code: function main(workbook: ExcelScript.Workbook) { console. ...

Establish an enumeration using universally recognized identifiers

I have a JavaScript function that requires a numerical input, as well as some predefined constants at the top level: var FOO = 1; var BAR = 2; The function should only be called using one of these constants. To ensure type safety in TypeScript, I am att ...

Predicate returning negative type assertion

I need help writing two Jest functions that can verify if an object is an instance of a specific type or not. The function expectInstanceOf works perfectly, but unfortunately, the function expectNotInstanceOf is not functioning as expected. export functio ...

Creating a visually appealing stacked bar chart using Chart.js in Angular 9 with multiple bars

Upon integrating Chart.js into my Angular 9 application, I encountered an issue where the expected chart values were not being displayed. In order to address this problem, I need to structure the barChartData according to the format showcased in this stac ...

Trigger a method within a component when there is a change in the Vuex state

I need to trigger a method inside a component whenever the vuex state changes in TypeScript and Vue.js. While I can access the vuex state value using getters in the template, I am unsure how to access the data within the component class. The vuex state is ...

Using Services in Angular 11: A Guide to Implementing Services in Regular Typescript Files

I'm working with a utils.ts file that contains exported functions like deepCopy and sortArray. However, I need to use a service within some of these functions. How can I go about incorporating a service, such as toastService, into my utils.ts file? // ...

What is the best way to monitor updates made to a function that utilizes firestore's onSnapShot method?

I am currently working with the following function: public GetExercisePosts(user: User): ExercisePost[] { const exercisePosts = new Array<ExercisePost>(); firebase.firestore().collection('exercise-posts').where('created-by&apo ...

The element 'mat-form-field' is unrecognized - Angular 4 and Angular Material 2 do not recognize it

Within my angular application, I have a presentation.module that manages all components. Additionally, I've established a shared-material.module which contains all Angular Material 2 modules utilized throughout the application. This module is imported ...