How to use @aws-cdk/aws-stepfunctions - 10 common examples

To help you get started, we’ve selected a few @aws-cdk/aws-stepfunctions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fourTheorem / slic-starter / cicd / lib / stages / build-job.ts View on Github external
constructor(scope: Construct, id: string, props: BuildJobProps) {
    super(scope, id)

    this.task = new Task(this, `${id} build`, {
      resource: props.runCodeBuildFunction,
      parameters: {
        codeBuildProjectArn: props.codeBuildProjectArn,
        'sourceLocation.$': props.sourceLocationPath
      },
      inputPath: '$',
      resultPath: `$.runBuildResult.${id}`,
      outputPath: '$' // Pass all input to the output
    })

    const checkBuildTask = new Task(this, `Check ${id} status`, {
      resource: props.checkCodeBuildFunction,
      parameters: {
        'build.$': `$.runBuildResult.${id}.build`
      },
      inputPath: `$`,
      resultPath: `$.buildStatus.${id}`,
      outputPath: '$'
    })

    const waitForBuild = new Wait(this, `Wait for ${id}`, {
      duration: WaitDuration.seconds(10)
    })

    this.task.next(waitForBuild)
    waitForBuild.next(checkBuildTask)
    checkBuildTask.next(
github fourTheorem / slic-starter / cicd / lib / stages / build-job.ts View on Github external
inputPath: '$',
      resultPath: `$.runBuildResult.${id}`,
      outputPath: '$' // Pass all input to the output
    })

    const checkBuildTask = new Task(this, `Check ${id} status`, {
      resource: props.checkCodeBuildFunction,
      parameters: {
        'build.$': `$.runBuildResult.${id}.build`
      },
      inputPath: `$`,
      resultPath: `$.buildStatus.${id}`,
      outputPath: '$'
    })

    const waitForBuild = new Wait(this, `Wait for ${id}`, {
      duration: WaitDuration.seconds(10)
    })

    this.task.next(waitForBuild)
    waitForBuild.next(checkBuildTask)
    checkBuildTask.next(
      new Choice(this, `${id} done?`)
        .when(
          Condition.stringEquals(
            `$.buildStatus.${id}.buildStatus`,
            'SUCCEEDED'
          ),
          new Succeed(this, `Success ${id}`)
        )
        .when(
          Condition.stringEquals(
github fourTheorem / slic-starter / cicd / lib / stages / build-job.ts View on Github external
resultPath: `$.runBuildResult.${id}`,
      outputPath: '$' // Pass all input to the output
    })

    const checkBuildTask = new Task(this, `Check ${id} status`, {
      resource: props.checkCodeBuildFunction,
      parameters: {
        'build.$': `$.runBuildResult.${id}.build`
      },
      inputPath: `$`,
      resultPath: `$.buildStatus.${id}`,
      outputPath: '$'
    })

    const waitForBuild = new Wait(this, `Wait for ${id}`, {
      duration: WaitDuration.seconds(10)
    })

    this.task.next(waitForBuild)
    waitForBuild.next(checkBuildTask)
    checkBuildTask.next(
      new Choice(this, `${id} done?`)
        .when(
          Condition.stringEquals(
            `$.buildStatus.${id}.buildStatus`,
            'SUCCEEDED'
          ),
          new Succeed(this, `Success ${id}`)
        )
        .when(
          Condition.stringEquals(
            `$.buildStatus.${id}.buildStatus`,
github aws / aws-cdk / packages / @aws-cdk / aws-stepfunctions-tasks / lib / sagemaker-train-task.ts View on Github external
constructor(private readonly props: SagemakerTrainTaskProps) {
        this.integrationPattern = props.integrationPattern || sfn.ServiceIntegrationPattern.FIRE_AND_FORGET;

        const supportedPatterns = [
            sfn.ServiceIntegrationPattern.FIRE_AND_FORGET,
            sfn.ServiceIntegrationPattern.SYNC
        ];

        if (!supportedPatterns.includes(this.integrationPattern)) {
            throw new Error(`Invalid Service Integration Pattern: ${this.integrationPattern} is not supported to call SageMaker.`);
        }

        // set the default resource config if not defined.
        this.resourceConfig = props.resourceConfig || {
            instanceCount: 1,
            instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.XLARGE),
            volumeSizeInGB: 10
        };

        // set the stopping condition if not defined
        this.stoppingCondition = props.stoppingCondition || {
github fourTheorem / slic-starter / cicd / lib / stages / build-modules-stage.ts View on Github external
)

      const buildJob = new BuildJob(
        this,
        `${moduleName}_${stageName}_build_job`,
        {
          codeBuildProjectArn: this.buildModuleProjects[moduleName].projectArn,
          checkCodeBuildFunction: props.checkCodeBuildFunction,
          runCodeBuildFunction: props.runCodeBuildFunction,
          sourceLocationPath: '$.sourceLocation'
        }
      )

      // TODO - Fix this
      const changesPath = true || stageNo === 1 ? '$' : `$.[${moduleIndex}]`
      const ifChangedChoice = new Choice(
        this,
        `${moduleName} changed? ${stageName} build`
      )
        .when(
          Condition.or(
            Condition.booleanEquals(
              `${changesPath}.changes.${moduleName}`,
              true
            ),
            Condition.booleanEquals(`${changesPath}.changes.all_modules`, true)
          ),
          buildJob.task
        )
        .otherwise(new Succeed(this, `Skip ${stageName} ${moduleName} build`))

      this.stageState.branch(ifChangedChoice)
github fourTheorem / slic-starter / cicd / lib / stages / build-job.ts View on Github external
constructor(scope: Construct, id: string, props: BuildJobProps) {
    super(scope, id)

    this.task = new Task(this, `${id} build`, {
      resource: props.runCodeBuildFunction,
      parameters: {
        codeBuildProjectArn: props.codeBuildProjectArn,
        'sourceLocation.$': props.sourceLocationPath
      },
      inputPath: '$',
      resultPath: `$.runBuildResult.${id}`,
      outputPath: '$' // Pass all input to the output
    })

    const checkBuildTask = new Task(this, `Check ${id} status`, {
      resource: props.checkCodeBuildFunction,
      parameters: {
        'build.$': `$.runBuildResult.${id}.build`
      },
      inputPath: `$`,
github aws / aws-cdk / packages / @aws-cdk / custom-resources / lib / provider-framework / provider.ts View on Github external
}

    this.onEventHandler = props.onEventHandler;
    this.isCompleteHandler = props.isCompleteHandler;

    const onEventFunction = this.createFunction(consts.FRAMEWORK_ON_EVENT_HANDLER_NAME);

    if (this.isCompleteHandler) {
      const isCompleteFunction = this.createFunction(consts.FRAMEWORK_IS_COMPLETE_HANDLER_NAME);
      const timeoutFunction = this.createFunction(consts.FRAMEWORK_ON_TIMEOUT_HANDLER_NAME);

      const isCompleteTask = this.createTask(isCompleteFunction);
      isCompleteTask.addCatch(this.createTask(timeoutFunction));
      isCompleteTask.addRetry(calculateRetryPolicy(props));

      const waiterStateMachine = new sfn.StateMachine(this, 'waiter-state-machine', {
        definition: isCompleteTask
      });

      // the on-event entrypoint is going to start the execution of the waiter
      onEventFunction.addEnvironment(consts.WAITER_STATE_MACHINE_ARN_ENV, waiterStateMachine.stateMachineArn);
      waiterStateMachine.grantStartExecution(onEventFunction);
    }

    this.entrypoint = onEventFunction;
  }
github fourTheorem / slic-starter / cicd / lib / stages / build-modules-stage.ts View on Github external
codeBuildProjectArn: this.buildModuleProjects[moduleName].projectArn,
          checkCodeBuildFunction: props.checkCodeBuildFunction,
          runCodeBuildFunction: props.runCodeBuildFunction,
          sourceLocationPath: '$.sourceLocation'
        }
      )

      // TODO - Fix this
      const changesPath = true || stageNo === 1 ? '$' : `$.[${moduleIndex}]`
      const ifChangedChoice = new Choice(
        this,
        `${moduleName} changed? ${stageName} build`
      )
        .when(
          Condition.or(
            Condition.booleanEquals(
              `${changesPath}.changes.${moduleName}`,
              true
            ),
            Condition.booleanEquals(`${changesPath}.changes.all_modules`, true)
          ),
          buildJob.task
        )
        .otherwise(new Succeed(this, `Skip ${stageName} ${moduleName} build`))

      this.stageState.branch(ifChangedChoice)
    })
  }
github fourTheorem / slic-starter / cicd / lib / stages / build-modules-stage.ts View on Github external
}
      )

      // TODO - Fix this
      const changesPath = true || stageNo === 1 ? '$' : `$.[${moduleIndex}]`
      const ifChangedChoice = new Choice(
        this,
        `${moduleName} changed? ${stageName} build`
      )
        .when(
          Condition.or(
            Condition.booleanEquals(
              `${changesPath}.changes.${moduleName}`,
              true
            ),
            Condition.booleanEquals(`${changesPath}.changes.all_modules`, true)
          ),
          buildJob.task
        )
        .otherwise(new Succeed(this, `Skip ${stageName} ${moduleName} build`))

      this.stageState.branch(ifChangedChoice)
    })
  }
github aws / aws-cdk / packages / @aws-cdk / aws-stepfunctions-tasks / lib / sagemaker-train-task.ts View on Github external
private makePolicyStatements(task: sfn.Task): iam.PolicyStatement[] {
        const stack = Stack.of(task);

        // https://docs.aws.amazon.com/step-functions/latest/dg/sagemaker-iam.html
        const policyStatements = [
            new iam.PolicyStatement({
                actions: ['sagemaker:CreateTrainingJob', 'sagemaker:DescribeTrainingJob', 'sagemaker:StopTrainingJob'],
                resources: [
                    stack.formatArn({
                        service: 'sagemaker',
                        resource: 'training-job',
                        // If the job name comes from input, we cannot target the policy to a particular ARN prefix reliably...
                        resourceName: sfn.Data.isJsonPathString(this.props.trainingJobName) ? '*' : `${this.props.trainingJobName}*`
                    })
                ],
            }),
            new iam.PolicyStatement({
                actions: ['sagemaker:ListTags'],
                resources: ['*']
            }),
            new iam.PolicyStatement({
                actions: ['iam:PassRole'],
                resources: [this._role!.roleArn],
                conditions: {
                    StringEquals: { "iam:PassedToService": "sagemaker.amazonaws.com" }
                }
            })
        ];