AWS StepFunctions: sum() function returns error about not finding path

0

I have a StepFunction with input:

{
  "Jobs": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]
}

and I want the sum of the values in this array. According to the Json-Path docs there should exist a .sum() function for this. When I try it here it even works. So I defined the following Pass state:

"Sum Jobs": {
  "Type": "Pass",
  "Parameters": {
   "Jobs.$": "$.Jobs.sum()"
  }
},

Nevertheless executions fail with:

"An error occurred while executing the state 'Sum Jobs' (entered at the event id #249). The JSONPath '$.Jobs.sum()' specified for the field 'Jobs.$' could not be found in the input '{\"Jobs\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]}'"
已提問 2 年前檢視次數 601 次
1 個回答
-1

AWS Step Functions does not support functions in the path reference. It uses JSONPath expressions to identify a node, however has the following constraints:

  • You can access object fields using only dot (.) and square bracket ([ ]) notation.
  • The operators @ .. , : ? * aren't supported.
  • Functions such as length() aren't supported.

This Step Functions documentation that covers this can be found here.

AWS
Steve
已回答 2 年前
  • This is only valid for Reference Paths: i.e. ItemsPath, ResultPath and OutputPath. However InputPath, Parameters and ResultSelector can use the whole JsonPath syntax. I use filter expressions in these regularly. If you read the docs closely it distinguishes between normal and reference paths in the section you linked to and then states in each section which path is a reference path. For example in the blue box here

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

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

回答問題指南