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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠