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]}'"
preguntada hace 2 años601 visualizaciones
1 Respuesta
-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
respondido hace 2 años
  • 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

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas