繁体   English   中英

Step Functions 参数(数组或不数组)

[英]Step Functions parameter (array or not to array)

我有几台 state 机器,它们分别使用DescribeNetworkInterfaces (和 EC2 API)和ListResourceRecordSets (Route53 API)。

我使用输入组成两个参数,如下所示:

对于 EC2:

      "Parameters": {
        "NetworkInterfaceIds.$": "$.detail.attachments[0].details[?(@.name==networkInterfaceId)].value"
      "Resource": "arn:aws:states:::aws-sdk:ec2:describeNetworkInterfaces",

对于 53 号公路:

      "Parameters": {
        "HostedZoneId.$": "$.NetworkInterfaces[0].TagSet[?(@.Key==HOSTZONEID)].Value"
      },
      "Resource": "arn:aws:states:::aws-sdk:route53:listResourceRecordSets"

它们解决得很好,但问题是,由于某些原因, [?(@.name=.networkInterfaceId)][?(@.Key==HOSTZONEID)]将参数值转换为数组。 分别:

{
  "NetworkInterfaceIds": [
    "eni-00f25c294401006b2"
  ]
}

和:

{
  "HostedZoneId": [
    "Z0555263BOXV8ELWLRS5"
  ]
}

在我的例子中,EC2 调用成功,因为网络 API 确实需要一个 ENI 数组。 然而,Route53 调用失败,因为记录 API 确实需要一个托管区域 ID。 这是我从 SF 收到的错误消息:

No hosted zone found with ID: ["Z0555263BOXV8ELWLRS5"] (Service: Route53, Status Code: 404, Request ID: fa5bc89b-ca3d-4fe9-b2f3-baf01d509d76)

根据我的测试,似乎是 select 导致参数变成数组,因为如果我直接指向一个字段(我不能这样做),例如:

      "Parameters": {
        "NetworkInterfaceIds.$": "States.Array($.detail.attachments[0].details[1].value)"
      },

输入参数不再构造为数组,网络 API 失败并显示:

An error occurred while executing the state 'DescribeNetworkInterfaces (1)' (entered at the event id #2). The Parameters '{"NetworkInterfaceIds":"eni-00f25c294401006b2"}' could not be used to start the Task: [Cannot construct instance of An error occurred while executing the state 'DescribeNetworkInterfaces (1)' (entered at the event id #2). The Parameters '{"NetworkInterfaceIds":"eni-00f25c294401006b2"}' could not be used to start the Task: [Cannot construct instance of (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('eni-00f25c294401006b2')]

我可以使用States.Array内部函数解决上述问题,但这是一个有争议的问题,因为我需要动态 select 输入中的值。

所以我正处于 EC2 调用工作的地步,因为偶然地,我需要一个数组......但我无法弄清楚如何将 Route53 参数(托管区域 ID)转换为非数组。

这比我想象的要容易。 我认为有一个内在函数可以让我从数组中提取一个值: States.ArrayGetItem

以下是诀窍:

      "Parameters": {
        "HostedZoneId.$": "States.ArrayGetItem($.NetworkInterfaces[0].TagSet[?(@.Key==HOSTZONEID)].Value, 0)"
      },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM