Get min/max value between 2 argument in step function

0

Hi I have scenario to get min value between 2 argument and compare it with constant to make condition true/false, I can see interstice function but don't get this method like min/max. Other than that, I can get this approach using lambda.

So since this simple operation, can I get this inside step function instead ?

質問済み 5ヶ月前518ビュー
2回答
1

There is no intrinsic function to get min/max of two numbers. Besides using a Lambda function, you can use a choice state to check which one of the two numbers is larger, and then another choice state to check if it is equal to the constant value.

profile pictureAWS
エキスパート
Uri
回答済み 5ヶ月前
0

As you noticed, there are no min/max functions available in Step Functions, however you can try something like this to compare two variables between each other and constant.

It's based on simple logic that can be coded as

a = 4
b = 5
const = 1

if a < b and a < const:
    print("a is smaller")
elif b < a and b < const:
    print("b is smaller")

Ecample (working) Step Function code:

{
  "Comment": "Check minimum state machine",
  "StartAt": "Choice",
  "States": {
    "Choice": {
      "Type": "Choice",
      "Choices": [
        {
          "And": [
            {
              "Variable": "$.a",
              "NumericLessThanPath": "$.b"
            },
            {
              "Variable": "$.a",
              "NumericLessThanPath": "$.const"
            }
          ],
          "Next": "A is smaller"
        },
        {
          "And": [
            {
              "Variable": "$.b",
              "NumericLessThanPath": "$.a"
            },
            {
              "Variable": "$.b",
              "NumericLessThanPath": "$.const"
            }
          ],
          "Next": "B is smaller"
        }
      ],
      "Default": "Const not reached"
    },
    "A is smaller": {
      "Type": "Pass",
      "End": true
    },
    "Const not reached": {
      "Type": "Pass",
      "End": true
    },
    "B is smaller": {
      "Type": "Pass",
      "End": true
    }
  }
}
回答済み 5ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ