Intrinsic Functions: Nested Array within ArrayContains

0

Is it possible to nest a States.Array within States.ArrayContains?

I have a variable in my Step Function which attempts this nesting

"ForceRun.$": "States.ArrayContains(States.Array($.args.firststage, $.args.all), true)"

but this yields the following error

An error occurred while executing the state 'firststage' (entered at the event id #29). There was an error while evaluating the intrinsic function: States.ArrayContains(States.Array($.args.firststage, $.args.all), true). Invalid arguments in States.ArrayContains

Is this an error on my part?

Update

To recreate the issue, create a step function which calls another step function as such:

{
  "Comment": "A description of my state machine",
  "StartAt": "Step Functions StartExecution",
  "States": {
    "Step Functions StartExecution": {
      "Type": "Task",
      "Resource": "arn:aws:states:::states:startExecution.sync:2",
      "Parameters": {
        "StateMachineArn": "arn:aws:states:eu-west-2:<account-id>:stateMachine:test-nested",
        "Input": {
          "ForceRun.$": "States.ArrayContains(States.Array($.firststage, $.all), true)"
        }
      },
      "End": true
    }
  }
}

Example input

{"firststage": false "all": true}
asked 7 months ago352 views
1 Answer
0

In official documentation, States.ArrayContains has the following limitations:

  • You must specify an array as the input value for function's first argument.
  • You must specify a valid JSON object as the second argument.
  • The input array can't exceed Step Functions' payload size limit of 256 KB.

I tried your example but I couldn't reproduce the error. Enter image description here

profile picture
HS
answered 7 months ago
  • I am also able to get it to work in the data flow simulator, but not in a state machine. I have updated my question showing how to recreate the issue.

  • Hmm... This is mysterious. The documentation says that you can nest up to 10 intrinsic functions within a field, but actually it is not likely to work for any type of the states.

    As a workaround, you can define a intermediate state to convert the inputs to array first, and pass the array to States.ArrayContains for further process.

    {
      "States": {
        "Intermediate": {
          "Next": "MainTask",
          "Parameters": {
            "TmpArray.$": "States.Array($.a, $.b)"
          },
          "Type": "Pass"
        },
        "MainTask": {
          "End": true,
          "Parameters": {
            "ForceRun.$": "States.ArrayContains($.TmpArray, true)"
          },
          "Type": "Pass"
        }
      }
    }
  • Thanks for the temporary work around! It would be great if this bug gets fixed rather than having to bloat my step function though.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions