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]}'"
gefragt vor 2 Jahren601 Aufrufe
1 Antwort
-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
beantwortet vor 2 Jahren
  • 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

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen