Create Step Functions from JSON File in CDK

Viewed 1114

With an existing Step Functions definition JSON file, how can I use it directly in CDK to create a Step Function?

2 Answers

Use the L1 CfnStateMachine construct. It has a definitionString prop that accepts a stringified JSON definition.

Here is the code snippet if it is useful to anyone.

  private createStepFunction(props: {
    stepfunction_name: string;
    stepfunctions_role_arn: string;
  }): stepfunctions.CfnStateMachine {
    const file = fs.readFileSync("../step_functions/definition.asl.json");

    const stepFunction = new stepfunctions.CfnStateMachine(
      this,
      "cfnStepFunction",
      {
        roleArn: props.stepfunctions_role_arn,
        definitionString: file.toString(),
        stateMachineName: props.stepfunction_name,
      }
    );

    return stepFunction;
  }
Related