'stateMachineArn' 处的值 null 未能满足约束:成员不得为 null

Value null at 'stateMachineArn' failed to satisfy constraint: Member must not be null

我遵循 AWS Step Functions 并添加了 AWS Step Functions。

但是当我使用下面的代码尝试调用 Step Functions 时,

import { ajax } from 'rxjs/ajax';

// ...
ajax.post(
  url,
  {
    input: JSON.stringify({
      formId: action.payload.formId,
      fields: action.payload.fields,
    }),
  },
  { 'Content-Type': 'application/json' },
).pipe(
  map(res => actions.sendRequestSucceed(res)),
  catchError(actions.sendRequestFailed),
)

它returns错误:

response: {
    message: "1 validation error detected: Value null at 'stateMachineArn' failed to satisfy constraint: Member must not be null"
    __type: "com.amazon.coral.validate#ValidationException"
}

我花了一段时间才弄明白。

首先需要设置API网关,可以关注this tutorial.

注意操作StartExecution

这里是StartExecutionAPI document

{
   "input": "string",
   "name": "string", (Optional)
   "stateMachineArn": "string"
}

添加 stateMachineArn 后,可以在您的 Step Functions -> State machines

中找到

代码中

ajax.post(
  url,
  {
    input: JSON.stringify({
      formId: action.payload.formId,
      fields: action.payload.fields,
    }),
    stateMachineArn: 'arn:aws:states:us-west-2:000000000000:stateMachine:SendFormStateMachine',
  },
  // ...

然后就可以了。

另请注意 StartExecution input 仅接受字符串。如果你需要传递一个对象,你可以使用 JSON.stringify.