簡體   English   中英

AWS Step Function NumericGreaterThan 參數

[英]AWS Step Function NumericGreaterThan a Parameter

在 AWS 步驟 Function 中,在選擇步驟中,我們希望將來自 AWS Lambda function 的結果與使用“NumericGreaterT”作為參數給出的閾值進行比較。

在我們的示例中,我們將根據 lambda 計算得出的值與事件給出的閾值進行比較。

我嘗試通過以下方式定義我的步驟 function:

{
  "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"
    }
  }
}

但收到錯誤Expected value of type: Integer, Float insted of String 如果我用硬編碼值(如 20)替換“$.threshold”,它可以工作,但該值不是我想要的動態值。

以下輸入應導致 lambda 到達成功 State:

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

我知道我們可以用另一個 Lambda function 替換選擇步驟,但出於成本效益問題,我們不想這樣做。

有誰知道如何解決這個問題?

您可以按照文檔https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html使用“NumericGreaterThanPath”運算符

在選擇規則中,通過將“路徑”附加到支持的比較運算符的名稱,可以將變量的值與來自 state 輸入的另一個值進行比較。

NumericEqualsPath、NumericGreaterThanPath、NumericGreaterThanEqualsPath 等。

比較運算符需要在“:”之后有一個 integer。 不能是字符串。

一種解決方法是將"Variable": "$.count"更改為"Variable": "$.count/$.threshold"以便您可以擁有"NumericGreaterThan": 1 在這種情況下,您有定義選擇操作的計數和閾值。

讓我知道這是否能解決您的問題

精度: "Variable": "$.count"變為"Variable": "$.ratio" ,其中ratio = count/threshold

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM