从 CDK 中的 JSON 文件创建 Step Functions

Qin*_*jie 4 amazon-web-services aws-step-functions aws-cdk

使用现有的 Step Functions 定义 JSON 文件,如何直接在 CDK 中使用它来创建 Step Function?

fed*_*nev 12

使用 L1CfnStateMachine构造。它有一个definitionString属性,它接受字符串化的JSON 定义。


Qin*_*jie 9

这是代码片段,如果它对任何人有用的话。

  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;
  }
Run Code Online (Sandbox Code Playgroud)