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}
已提問 7 個月前檢視次數 385 次
1 個回答
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
已回答 7 個月前
  • 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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南