带有 waitForTaskToken 的 Aws StepFunction 路径

Aws StepFunction path with waitForTaskToken

我无法将状态“PublishIotCmd&WaitTask”的输入路径转发到下一个任务“succedTask”。

state disgram picture

假设“PublishIotCmd&WaitTask”的输入路径是{“fuzzy”:“foo”}。

“PublishIotCmd&WaitTask”被外部lamba唤醒,让我们模拟一下:

aws stepfunctions send-task-success --task-token <the_token>--task-output {\"a\":\"b\"},

我希望“succedTask”的输入路径是:

{
  "fuzzy":"foo"
  "taskresult": {"a":"b"}
}

这是任务定义:

"PublishIotCmd&WaitTask": {
 "Type": "Task",
"TimeoutSeconds": 600,
"Resource": "arn:aws:states:::lambda:invoke.waitForTaskToken",
      "Parameters": {
        "FunctionName": "XXX",
        "Payload": {
          "token.$": "$$.Task.Token",
          "request.$": "$",
          "resultPath": "$.taskresult"
        }
      }
}

此状态定义由以下 cdk 代码生成:

const publishIot = new tasks.LambdaInvoke(this, 'PublishIotCmd&WaitTask', {
  lambdaFunction: iotSendCommandFn,
  payload: sfn.TaskInput.fromObject({
    token: sfn.JsonPath.taskToken,
    request: sfn.JsonPath.entirePayload,
    resultPath: '$.lambda',       
  }),
  integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
  timeout: Duration.minutes(TIMEOUT_WAIT_REPLY_SECONDS),
});

@Anton 提出的建议: “或者将输入作为 PublishIotCmd 的输出传递。”:我猜你的意思是这样的:

   "Payload": {
     "token.$": "$$.Task.Token",
      "request.$": "$",
      "resultPath": "$.lambda",
       "outputPath": "$"
    }

但这仍然不起作用,我只得到 {“a”:“b”}

我认为您想将 resultPath 传递给 props 而不是 payload

const publishIot = new tasks.LambdaInvoke(
  this, 
  'PublishIotCmd&WaitTask',
  {
    lambdaFunction: iotSendCommandFn,
    payload: sfn.TaskInput.fromObject({
      token: sfn.JsonPath.taskToken,
      request: sfn.JsonPath.entirePayload,     
    }),
    integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
    timeout: Duration.minutes(TIMEOUT_WAIT_REPLY_SECONDS),
    resultPath: '$.lambda',
  }
);

@Marco,您不需要为 PublishIotCmd&WaitTask 指定输出路径。只需为 succedTask 指定负载,如下所示

"Payload": {
  "fuzzy":"foo",
  "taskresult.$": "$."
}

这样 succedTask 的输入将是

{
  "fuzzy":"foo",
  "taskresult": {"a":"b"}
}