AWS Step函数:在选择状态下,函数.length()在变量字段中返回错误 [英] AWS Step Function: Function .length() returned error in variable field in Choice state

查看:77
本文介绍了AWS Step函数:在选择状态下,函数.length()在变量字段中返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AWS Step Function中有一个Choice状态,该状态将比较Input中数组的长度,并决定进入下一个状态.

I have a Choice state in AWS Step Function that would compare an array's length from Input and make decision to go next state.

但是, length()函数要获取数组的长度,会返回错误:

However, the length() function, to get the array's length, returned an error:

{
错误":"States.Runtime",
原因":在执行状态'CheckItemsCountState'时发生错误(在事件ID#18处输入).无效的路径'$ .Metadata [2] .Items.length()':选择状态的条件路径引用了无效的值."

{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'CheckItemsCountState' (entered at the event id #18). Invalid path '$.Metadata[2].Items.length()': The choice state's condition path references an invalid value."

}

选择状态的定义如下:

     "CheckItemsCountState":{  
         "Type": "Choice",
         "InputPath": "$",
         "OutputPath": "$",
         "Default": "NoItemsState",
         "Choices":[  
            {  
               "Variable": "$.Metadata[2].Items.length()",
               "NumericGreaterThan": 0,
               "Next": "ProcessState"
            }
         ]
      },

该状态与其他返回JSON的状态连接.JSON如下:

The state is connected some other state that returns a JSON. The JSON is as below:

{
  "Metadata": [
    {
      "foo": "name"
    },
    {
      "Status": "COMPLETED"
    },
    {
      "Items": []
    }
  ]
}

因此,我试图在 Metadata [2] 中获取 Items 的长度,并进行比较(如果该值大于0).

So I was trying to get the length of Items in Metadata[2] and make comparison if the value is greater than 0.

我已尝试在此

I have tried to validate the JsonPath $.Metadata[2].Items.length() in this website and it returns 0.

我不确定是否错过了任何事情.我在AWS Step Function的文档中或在jsonpath中使用函数的示例中找不到任何信息.

I am not sure if I've missed anything. I couldn't find any information in AWS Step Function's docs or example on using function in jsonpath.

我将不胜感激.谢谢!

推荐答案

步骤函数不允许您使用函数来获取值.从

Step Functions do not allow you to use functions to get values. From the Choice Rules documentation:

对于每个这些运算符,其对应值必须为适当的类型:字符串,数字,布尔值或时间戳.

For each of these operators, the corresponding value must be of the appropriate type: string, number, Boolean, or timestamp.

要执行您要的操作,您需要获取上一个函数中的数组长度,并将其作为输出的一部分返回.

To do what you're asking, you would need to get the array length in the previous function and return it as part of the output.

{
  "Metadata": [
    {
      "foo": "name"
    },
    {
      "Status": "COMPLETED"
    },
    {
      "Items": [],
      "ItemsCount": 0
    }
  ]
}

然后在步骤功能选择"步骤中:

Then in the Step Function Choice step:

"CheckItemsCountState":{  
    "Type": "Choice",
    "InputPath": "$",
    "OutputPath": "$",
    "Default": "NoItemsState",
    "Choices":[  
        {  
            "Variable": "$.Metadata[2].ItemsCount",
            "NumericGreaterThan": 0,
            "Next": "ProcessState"
        }
    ]
},

这篇关于AWS Step函数:在选择状态下,函数.length()在变量字段中返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆