如何使用 aws cdk 打字稿创建 aws 步骤函数?

时间:2021-02-25 16:06:17

标签: typescript amazon-web-services aws-lambda aws-cdk aws-step-functions

我想使用 aws cdk typescript 创建以下步骤函数。 这是代码片段截图: enter image description here 我在打字稿中尝试了以下代码:

const finalStep = new sfn.Pass(this, 'FinalStep');
    
    const fallBackJson={
      Type: "Task",
      Resource: "lambdaARN",
      ResultPath: "$.taskresult",
      InputPath: "$",
      Next: "FinalStep"
    };
    // States language JSON to put an item into DynamoDB
    // snippet generated from https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-code-snippet.html#tutorial-code-snippet-1
    const startRecordingJson = {
        Type: "Task",
        Resource: joinMeetingLambda.functionArn,
        Parameters: {
          "meetingId.$": "$.meetingId",
          "projectId.$": "$.projectId",
          "meetingURL.$": "$.meetingURL",
          "subscriptionId.$": "$.subscriptionId",
          "recordingAction": "start"
        },
        Retry: [
          {
            "ErrorEquals": [
              "RecordingFailedToStart"
            ],
            "IntervalSeconds": 1,
            "MaxAttempts": 5,
            "BackoffRate": 2
          }
        ],
        Catch: [
          {
            "ErrorEquals": [
              "RecordingFailedToStart"
            ],
            Next: "FallBack"
          }
        ]
    };
    
    // custom state which represents a task to insert data into DynamoDB
    const startRecordingState = new sfn.CustomState(this, 'InvokeRecording', {
      stateJson: startRecordingJson,
    });
    const fallBackState = new sfn.CustomState(this, 'FallBack', {
      fallBackJson,
    });
    
     const chain = sfn.Chain.start(startRecordingState)
           .next(finalStep)
     const sm = new sfn.StateMachine(this, 'StateMachine', {
  definition: chain ,
  timeout: cdk.Duration.seconds(30),
});
运行部署时出现以下错误:

Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The field 'Type' is required at /States/FallBack'

希望我能得到一些帮助。这是来自 aws 的状态图: enter image description here

0 个答案:

没有答案