Skip to content

bug: StepFunctions JSONPath evaluation #12318

Closed
@marcodallasanta

Description

@marcodallasanta

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Noticed a behaviour of JSONPath in stepfunctions that is different from what happens in a real AWS environment and from RFC9535.

When executing a JSONPath on an array which selects a portion or all of the elements of it, but the key of the array does not exist in the JSON input, the execution of the State fails.

The errors being logged are:

2025-02-28T16:17:04.153 ERROR --- [-1301 (eval)] l.s.s.a.c.eval_component   : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "The JSONPath $[*].type specified for the field types.$ could not be found in the input {}"}} at '(PayloadBindingPath| {'field': 'types', 'path': '$[*].type'}'
2025-02-28T16:17:04.153 ERROR --- [-1301 (eval)] l.s.s.a.c.eval_component   : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "The JSONPath $[*].type specified for the field types.$ could not be found in the input {}"}} at '(PayloadTmpl| {'payload_bindings': [(PayloadBindingPath| {'field': 'types', 'path': '$[*].type'}]}'
2025-02-28T16:17:04.153 ERROR --- [-1301 (eval)] l.s.s.a.c.eval_component   : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "The JSONPath $[*].type specified for the field types.$ could not be found in the input {}"}} at '(Parameters| {'payload_tmpl': (PayloadTmpl| {'payload_bindings': [(PayloadBindingPath| {'field': 'types', 'path': '$[*].type'}]}}'
2025-02-28T16:17:04.154 ERROR --- [-1301 (eval)] l.s.s.a.c.eval_component   : Exception=FailureEventException, Error=States.Runtime, Details={"taskFailedEventDetails": {"error": "States.Runtime", "cause": "The JSONPath $[*].type specified for the field types.$ could not be found in the input {}"}} at '(StatePass| {'comment': None, 'input_path': (InputPath| {'path': '$'}, 'output_path': (OutputPath| {'output_path': '$'}, 'state_entered_event_type': <HistoryEventType.PassStateEntered: 'PassStateEntered'>, 'state_exited_event_type': <HistoryEventType.PassStateExited: 'PassStateExited'>, 'result': None, 'result_path': (ResultPath| {'result_path_src': '$'}, 'parameters': (Parameters| {'payload_tmpl': (PayloadTmpl| {'payload_bindings': [(PayloadBindingPath| {'field': 'types', 'path': '$[*].type'}]}}, 'name': 'Pass', 'state_type': <StateType.Pass: 20>, 'continue_with': <localstack.services.stepfunctions.asl.component.state.state_continue_with.ContinueWithEnd object at 0xffff57e56010>}'

On a describe-state-machine command this is the result:

{
    "executionArn": "arn:aws:states:eu-west-2:000000000000:execution:test:fdd96225-9cdb-43d8-b1d6-071caaf67ded",
    "stateMachineArn": "arn:aws:states:eu-west-2:000000000000:stateMachine:test",
    "name": "fdd96225-9cdb-43d8-b1d6-071caaf67ded",
    "status": "FAILED",
    "startDate": "2025-02-28T16:36:26.234979+00:00",
    "stopDate": "2025-02-28T16:36:26.383306+00:00",
    "input": "{}",
    "inputDetails": {
        "included": true
    },
    "error": "States.Runtime",
    "cause": "An error occurred while executing the state 'Pass' (entered at the event id #2). The JSONPath $[*].type specified for the field types.$ could not be found in the input {}"
}

The steps to reproduce section contains the steps required to reproduce the above issue.

Expected Behavior

A JSONPath that selects some or all of the elements in an array, executed on a missing field, should return an empty array.
No errors should be logged, nor the execution should fail.

How are you starting LocalStack?

With a docker run command

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

 docker run --rm --name "localstack-main" -p 4566:4566 localstack/localstack:3.8.1

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

  • Create a state machine which contains a valid JSONPath expression which selects all the elements within an array:
awslocal stepfunctions create-state-machine --name "test" --definition '{
  "StartAt": "Pass",
  "States": {
    "Pass": {
      "Type": "Pass",
      "End": true,
      "Parameters": {
        "types.$": "$[*].type"
      }
    }
  }
}' --role-arn 'dummy'
  • Start an execution and omit such array in the input:
awslocal stepfunctions start-execution --state-machine-arn "<arn-from-the-output-of-create-state-machine>" --input '{}'
  • Describe the state machine
awslocal stepfunctions describe-execution --execution-arn "<arn-from-the-start-execution-command>"

Environment

- OS: MacOS Sequoia Version 15.3.1, M1
- LocalStack: 
  LocalStack version: 3.8.1, but similar behaviour on latest build
  LocalStack Docker image sha: sha256:b279c01f4cfb8f985a482e4014cabc1e2697b9d7a6c8c8db2e40f4d9f93687c7
  LocalStack build date: 2024-10-08
  LocalStack build git hash: 529aba7d8

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions