代码之家  ›  专栏  ›  技术社区  ›  Hongbo Miao

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

  •  0
  • Hongbo Miao  · 技术社区  · 6 年前

    我跟着 AWS Step Functions

    但是当我使用下面的代码试图调用Step函数时,

    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),
    )
    

    它返回错误:

    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"
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Hongbo Miao    6 年前

    我花了点时间才弄明白。

    首先需要设置API网关,您可以按照 this tutorial .

    enter image description here

    注意 行动 StartExecution .

    恒星观测 API document

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

    添加后 stateMachineArn

    enter image description here

    在代码中

    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

    推荐文章