Issue with AWS Step Functions Choice Condition Not Triggering Lambda State Correctly

0

I'm encountering an issue in my AWS Step Functions setup where I'm using a Choice state to trigger different Lambda states based on conditions. The choice condition is supposed to evaluate an input value, and based on that, either the "Goalstate" or "Assistsstate" should be triggered. However, it defaults to the "DefaultState" with the error "No valid condition matched." Here is a simplified version of my state machine configuration: { "QueryLanguage": "JSONata", "StartAt": "Choice", "States": { "Choice": { "Type": "Choice", "Choices": [ { "Condition": "{% $type = 'Goal' %}", "Next": "Goalstate" }, { "Condition": "{% $type = 'Assist' %}", "Next": "Assistsstate" } ], "Default": "DefaultState" }, "Goalstate": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Next": "Result" }, "Assistsstate": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Next": "Result" }, "DefaultState": { "Type": "Fail", "Error": "UnknownCondition", "Cause": "No valid condition matched" } } } The input I am passing: { "type": "Goal" }

2 Answers
1

Your Choice state should look at $states.input.type, otherwise, it is looking for a variable names type, which you did not declare.

profile pictureAWS
EXPERT
answered 25 days ago
profile picture
EXPERT
reviewed 25 days ago
0

Hi Srini,

I tried to use your State machine query to execute. All you need to modify in your configuration is Condition part as follows:

"Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "Condition": "{% $states.input.type = 'Goal' %}",
          "Next": "Goalstate"
        },
        {
          "Condition": "{% $states.input.type = 'Assist' %}",
          "Next": "Assistsstate"
        }
      ],
      "Default": "DefaultState"
    }

This will make the state machine pass through to "Goal" state. State machine run

You can see a similar example here: https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html

Thanks, Atul

profile picture
answered 25 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions