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

  • import * as iam from '@aws-cdk/aws-iam';
    import * as sfn from '@aws-cdk/aws-stepfunctions';
    
    const rule = new events.Rule(this, 'Rule', {
      schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
    });
    
    const dlq = new sqs.Queue(this, 'DeadLetterQueue');
    
    const role = new iam.Role(this, 'Role', {
      assumedBy: new iam.ServicePrincipal('events.amazonaws.com'),
    });
    const stateMachine = new sfn.StateMachine(this, 'SM', {
      definition: new sfn.Wait(this, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }),
      role,
    });
    
    rule.addTarget(new targets.SfnStateMachine(stateMachine, {
      input: events.RuleTargetInput.fromObject({ SomeParam: 'SomeValue' }),
      deadLetterQueue: dlq,
    }));
    
    Docs
    0
  • const convertToSeconds = new tasks.EvaluateExpression(this, 'Convert to seconds', {
      expression: '$.waitMilliseconds / 1000',
      resultPath: '$.waitSeconds',
    });
    
    const createMessage = new tasks.EvaluateExpression(this, 'Create message', {
      // Note: this is a string inside a string.
      expression: '`Now waiting ${$.waitSeconds} seconds...`',
      runtime: lambda.Runtime.NODEJS_14_X,
      resultPath: '$.message',
    });
    
    const publishMessage = new tasks.SnsPublish(this, 'Publish message', {
      topic: new sns.Topic(this, 'cool-topic'),
      message: sfn.TaskInput.fromJsonPathAt('$.message'),
      resultPath: '$.sns',
    });
    
    const wait = new sfn.Wait(this, 'Wait', {
      time: sfn.WaitTime.secondsPath('$.waitSeconds'),
    });
    
    new sfn.StateMachine(this, 'StateMachine', {
      definition: convertToSeconds
        .next(createMessage)
        .next(publishMessage)
        .next(wait),
    });
    
    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 convertToSeconds = new tasks.EvaluateExpression(this, 'Convert to seconds', {
      expression: '$.waitMilliseconds / 1000',
      resultPath: '$.waitSeconds',
    });
    
    const createMessage = new tasks.EvaluateExpression(this, 'Create message', {
      // Note: this is a string inside a string.
      expression: '`Now waiting ${$.waitSeconds} seconds...`',
      runtime: lambda.Runtime.NODEJS_14_X,
      resultPath: '$.message',
    });
    
    const publishMessage = new tasks.SnsPublish(this, 'Publish message', {
      topic: new sns.Topic(this, 'cool-topic'),
      message: sfn.TaskInput.fromJsonPathAt('$.message'),
      resultPath: '$.sns',
    });
    
    const wait = new sfn.Wait(this, 'Wait', {
      time: sfn.WaitTime.secondsPath('$.waitSeconds'),
    });
    
    new sfn.StateMachine(this, 'StateMachine', {
      definition: convertToSeconds
        .next(createMessage)
        .next(publishMessage)
        .next(wait),
    });
    
    Docs
    0
  • import * as iam from '@aws-cdk/aws-iam';
    import * as sfn from '@aws-cdk/aws-stepfunctions';
    
    const rule = new events.Rule(this, 'Rule', {
      schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
    });
    
    const dlq = new sqs.Queue(this, 'DeadLetterQueue');
    
    const role = new iam.Role(this, 'Role', {
      assumedBy: new iam.ServicePrincipal('events.amazonaws.com'),
    });
    const stateMachine = new sfn.StateMachine(this, 'SM', {
      definition: new sfn.Wait(this, 'Hello', { time: sfn.WaitTime.duration(cdk.Duration.seconds(10)) }),
      role,
    });
    
    rule.addTarget(new targets.SfnStateMachine(stateMachine, {
      input: events.RuleTargetInput.fromObject({ SomeParam: 'SomeValue' }),
      deadLetterQueue: dlq,
    }));
    
    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