Search code examples
amazon-web-servicesaws-step-functions

AWS Step Function NumericGreaterThan a Parameter


In an AWS Step Function, in a Choice step, we want to compare a result from an AWS Lambda function to a threshold given as a parameter using "NumericGreaterThan".

In our example, we compare a calculated from a lambda with a threshold given by the event.

I tried defining my step function in the following way:

{
  "StartAt": "Check Enough Data",
  "States": {
    "Check Enough Data": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ID:function:FUNCTION:$LATEST",
      "Next": "Validate Count",
      "ResultPath": "$.count"
    },
    "Validate Count": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.count",
          "NumericGreaterThan": "$.threshold",
          "Next": "Succeed State"
        }
      ],
      "Default": "Wait 24 Hours"
    },
    "Wait 24 Hours": {
      "Type": "Wait",
      "Seconds": 86400,
      "Next": "Check Enough Data"
    },
    "Succeed State": {
      "Type": "Succeed"
    }
  }
}

but got an error Expected value of type: Integer, Float insted of String. If I replace "$.threshold" with a hard-coded value (like 20), it works, but the value is not dynamic as I want.

The following input should cause the lambda to get to the Succeed State:

{
   "country": "japan",
   "threshold": 40
}

I know we can replace the Choice step with another Lambda function, but we do not want to do that from cost-effective issues.

Does anyone have an idea on how to solve the problem?


Solution

  • you can use 'NumericGreaterThanPath' operator as per the docs https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html

    Within a Choice Rule, the value of Variable can be compared with another value from the state input by appending 'Path' to name of supported comparison operators.

    NumericEqualsPath, NumericGreaterThanPath, NumericGreaterThanEqualsPath, etc.