Search code examples
javascriptaws-api-gatewayaws-step-functions

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


I followed AWS Step Functions and added the AWS Step Functions.

But when I used the code below to try to call the 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),
)

It returns the error:

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"
}

Solution

  • Took me a while to figure out.

    First need set up API Gateway, you can follow this tutorial.

    enter image description here

    Note the Action is StartExecution.

    Here is StartExecution API document.

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

    After adding stateMachineArn which can be found at in your Step Functions -> State machines

    enter image description here

    in the code

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

    Then it works.

    Also note StartExecution input only accept string. If you need pass an object, you can use JSON.stringify.