How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • const choice = new sfn.Choice(this, 'Did it work?');
    
    // Add conditions with .when()
    const successState = new sfn.Pass(this, 'SuccessState');
    const failureState = new sfn.Pass(this, 'FailureState');
    choice.when(sfn.Condition.stringEquals('$.status', 'SUCCESS'), successState);
    choice.when(sfn.Condition.numberGreaterThan('$.attempts', 5), failureState);
    
    // Use .otherwise() to indicate what should be done if none of the conditions match
    const tryAgainState = new sfn.Pass(this, 'TryAgainState');
    choice.otherwise(tryAgainState);
    
    Docs
    0
  • import * as lambda from '@aws-cdk/aws-lambda';
    
    declare const submitLambda: lambda.Function;
    declare const getStatusLambda: lambda.Function;
    
    const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
      lambdaFunction: submitLambda,
      // Lambda's result is in the attribute `Payload`
      outputPath: '$.Payload',
    });
    
    const waitX = new sfn.Wait(this, 'Wait X Seconds', {
      time: sfn.WaitTime.secondsPath('$.waitSeconds'),
    });
    
    const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
      lambdaFunction: getStatusLambda,
      // Pass just the field named "guid" into the Lambda, put the
      // Lambda's result in a field called "status" in the response
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const jobFailed = new sfn.Fail(this, 'Job Failed', {
      cause: 'AWS Batch Job Failed',
      error: 'DescribeJob returned FAILED',
    });
    
    const finalStatus = new tasks.LambdaInvoke(this, 'Get Final Job Status', {
      lambdaFunction: getStatusLambda,
      // Use "guid" field as input
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const definition = submitJob
      .next(waitX)
      .next(getStatus)
      .next(new sfn.Choice(this, 'Job Complete?')
        // Look at the "status" field
        .when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
        .when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
        .otherwise(waitX));
    
    new sfn.StateMachine(this, 'StateMachine', {
      definition,
      timeout: Duration.minutes(5),
    });
    
    Docs
    0
  • const choice = new sfn.Choice(this, 'Did it work?');
    
    // Add conditions with .when()
    const successState = new sfn.Pass(this, 'SuccessState');
    const failureState = new sfn.Pass(this, 'FailureState');
    choice.when(sfn.Condition.stringEquals('$.status', 'SUCCESS'), successState);
    choice.when(sfn.Condition.numberGreaterThan('$.attempts', 5), failureState);
    
    // Use .otherwise() to indicate what should be done if none of the conditions match
    const tryAgainState = new sfn.Pass(this, 'TryAgainState');
    choice.otherwise(tryAgainState);
    
    Docs
    0
  • import { Construct, Stack } from '@aws-cdk/core';
    import * as sfn from '@aws-cdk/aws-stepfunctions';
    import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
    
    interface MyJobProps {
      jobFlavor: string;
    }
    
    class MyJob extends sfn.StateMachineFragment {
      public readonly startState: sfn.State;
      public readonly endStates: sfn.INextable[];
    
      constructor(parent: Construct, id: string, props: MyJobProps) {
        super(parent, id);
    
        const choice = new sfn.Choice(this, 'Choice')
          .when(sfn.Condition.stringEquals('$.branch', 'left'), new sfn.Pass(this, 'Left Branch'))
          .when(sfn.Condition.stringEquals('$.branch', 'right'), new sfn.Pass(this, 'Right Branch'));
    
        // ...
    
        this.startState = choice;
        this.endStates = choice.afterwards().endStates;
      }
    }
    
    class MyStack extends Stack {
      constructor(scope: Construct, id: string) {
        super(scope, id);
        // Do 3 different variants of MyJob in parallel
        new sfn.Parallel(this, 'All jobs')
          .branch(new MyJob(this, 'Quick', { jobFlavor: 'quick' }).prefixStates())
          .branch(new MyJob(this, 'Medium', { jobFlavor: 'medium' }).prefixStates())
          .branch(new MyJob(this, 'Slow', { jobFlavor: 'slow' }).prefixStates());
      }
    }
    
    Docs
    0
  • import * as lambda from '@aws-cdk/aws-lambda';
    
    declare const submitLambda: lambda.Function;
    declare const getStatusLambda: lambda.Function;
    
    const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
      lambdaFunction: submitLambda,
      // Lambda's result is in the attribute `Payload`
      outputPath: '$.Payload',
    });
    
    const waitX = new sfn.Wait(this, 'Wait X Seconds', {
      time: sfn.WaitTime.secondsPath('$.waitSeconds'),
    });
    
    const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
      lambdaFunction: getStatusLambda,
      // Pass just the field named "guid" into the Lambda, put the
      // Lambda's result in a field called "status" in the response
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const jobFailed = new sfn.Fail(this, 'Job Failed', {
      cause: 'AWS Batch Job Failed',
      error: 'DescribeJob returned FAILED',
    });
    
    const finalStatus = new tasks.LambdaInvoke(this, 'Get Final Job Status', {
      lambdaFunction: getStatusLambda,
      // Use "guid" field as input
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const definition = submitJob
      .next(waitX)
      .next(getStatus)
      .next(new sfn.Choice(this, 'Job Complete?')
        // Look at the "status" field
        .when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
        .when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
        .otherwise(waitX));
    
    new sfn.StateMachine(this, 'StateMachine', {
      definition,
      timeout: Duration.minutes(5),
    });
    
    Docs
    0
  • import { Construct, Stack } from '@aws-cdk/core';
    import * as sfn from '@aws-cdk/aws-stepfunctions';
    import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
    
    interface MyJobProps {
      jobFlavor: string;
    }
    
    class MyJob extends sfn.StateMachineFragment {
      public readonly startState: sfn.State;
      public readonly endStates: sfn.INextable[];
    
      constructor(parent: Construct, id: string, props: MyJobProps) {
        super(parent, id);
    
        const choice = new sfn.Choice(this, 'Choice')
          .when(sfn.Condition.stringEquals('$.branch', 'left'), new sfn.Pass(this, 'Left Branch'))
          .when(sfn.Condition.stringEquals('$.branch', 'right'), new sfn.Pass(this, 'Right Branch'));
    
        // ...
    
        this.startState = choice;
        this.endStates = choice.afterwards().endStates;
      }
    }
    
    class MyStack extends Stack {
      constructor(scope: Construct, id: string) {
        super(scope, id);
        // Do 3 different variants of MyJob in parallel
        new sfn.Parallel(this, 'All jobs')
          .branch(new MyJob(this, 'Quick', { jobFlavor: 'quick' }).prefixStates())
          .branch(new MyJob(this, 'Medium', { jobFlavor: 'medium' }).prefixStates())
          .branch(new MyJob(this, 'Slow', { jobFlavor: 'slow' }).prefixStates());
      }
    }
    
    Docs
    0
  • const choice = new sfn.Choice(this, 'Did it work?');
    
    // Add conditions with .when()
    const successState = new sfn.Pass(this, 'SuccessState');
    const failureState = new sfn.Pass(this, 'FailureState');
    choice.when(sfn.Condition.stringEquals('$.status', 'SUCCESS'), successState);
    choice.when(sfn.Condition.numberGreaterThan('$.attempts', 5), failureState);
    
    // Use .otherwise() to indicate what should be done if none of the conditions match
    const tryAgainState = new sfn.Pass(this, 'TryAgainState');
    choice.otherwise(tryAgainState);
    
    Docs
    0
  • import { Construct, Stack } from '@aws-cdk/core';
    import * as sfn from '@aws-cdk/aws-stepfunctions';
    import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
    
    interface MyJobProps {
      jobFlavor: string;
    }
    
    class MyJob extends sfn.StateMachineFragment {
      public readonly startState: sfn.State;
      public readonly endStates: sfn.INextable[];
    
      constructor(parent: Construct, id: string, props: MyJobProps) {
        super(parent, id);
    
        const choice = new sfn.Choice(this, 'Choice')
          .when(sfn.Condition.stringEquals('$.branch', 'left'), new sfn.Pass(this, 'Left Branch'))
          .when(sfn.Condition.stringEquals('$.branch', 'right'), new sfn.Pass(this, 'Right Branch'));
    
        // ...
    
        this.startState = choice;
        this.endStates = choice.afterwards().endStates;
      }
    }
    
    class MyStack extends Stack {
      constructor(scope: Construct, id: string) {
        super(scope, id);
        // Do 3 different variants of MyJob in parallel
        new sfn.Parallel(this, 'All jobs')
          .branch(new MyJob(this, 'Quick', { jobFlavor: 'quick' }).prefixStates())
          .branch(new MyJob(this, 'Medium', { jobFlavor: 'medium' }).prefixStates())
          .branch(new MyJob(this, 'Slow', { jobFlavor: 'slow' }).prefixStates());
      }
    }
    
    Docs
    0
  • import * as lambda from '@aws-cdk/aws-lambda';
    
    declare const submitLambda: lambda.Function;
    declare const getStatusLambda: lambda.Function;
    
    const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
      lambdaFunction: submitLambda,
      // Lambda's result is in the attribute `Payload`
      outputPath: '$.Payload',
    });
    
    const waitX = new sfn.Wait(this, 'Wait X Seconds', {
      time: sfn.WaitTime.secondsPath('$.waitSeconds'),
    });
    
    const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
      lambdaFunction: getStatusLambda,
      // Pass just the field named "guid" into the Lambda, put the
      // Lambda's result in a field called "status" in the response
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const jobFailed = new sfn.Fail(this, 'Job Failed', {
      cause: 'AWS Batch Job Failed',
      error: 'DescribeJob returned FAILED',
    });
    
    const finalStatus = new tasks.LambdaInvoke(this, 'Get Final Job Status', {
      lambdaFunction: getStatusLambda,
      // Use "guid" field as input
      inputPath: '$.guid',
      outputPath: '$.Payload',
    });
    
    const definition = submitJob
      .next(waitX)
      .next(getStatus)
      .next(new sfn.Choice(this, 'Job Complete?')
        // Look at the "status" field
        .when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
        .when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
        .otherwise(waitX));
    
    new sfn.StateMachine(this, 'StateMachine', {
      definition,
      timeout: Duration.minutes(5),
    });
    
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples