简体   繁体   English

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

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

I have a couple of state machines that use respectively DescribeNetworkInterfaces (and EC2 API) and ListResourceRecordSets (a Route53 API).我有几台 state 机器,它们分别使用DescribeNetworkInterfaces (和 EC2 API)和ListResourceRecordSets (Route53 API)。

I compose both Parameters using the Input as follows:我使用输入组成两个参数,如下所示:

For EC2:对于 EC2:

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

For Route 53:对于 53 号公路:

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

They resolve fine but the problem is that, for some reasons, the [?(@.name=.networkInterfaceId)] and the [?(@.Key==HOSTZONEID)] turn the Parmeters values into array.它们解决得很好,但问题是,由于某些原因, [?(@.name=.networkInterfaceId)][?(@.Key==HOSTZONEID)]将参数值转换为数组。 Respectively:分别:

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

And:和:

{
  "HostedZoneId": [
    "Z0555263BOXV8ELWLRS5"
  ]
}

In my case, the EC2 call succeeds because the Network API does expect an array of ENIs.在我的例子中,EC2 调用成功,因为网络 API 确实需要一个 ENI 数组。 However the Route53 call fails because the Records API does expect just one hosted zone id.然而,Route53 调用失败,因为记录 API 确实需要一个托管区域 ID。 This is the error message I get from SF:这是我从 SF 收到的错误消息:

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

Based on my tests, it seems that it's the select that is causing the Parameter to be turned into an array because if I point directly to a field (which I cannot do) such as this:根据我的测试,似乎是 select 导致参数变成数组,因为如果我直接指向一个字段(我不能这样做),例如:

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

The input parameter is no longer constructed as an array and the Network API fails with:输入参数不再构造为数组,网络 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 java.util.ArrayList (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('eni-00f25c294401006b2')] 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')]

I can fix the above problem using the States.Array intrinsic but it's a moot point because I need to dynamically select the the values in the inputs.我可以使用States.Array内部函数解决上述问题,但这是一个有争议的问题,因为我需要动态 select 输入中的值。

So I am at the point where the EC2 call works because, by chance, I need an array... but I can't figure out how to turn the Route53 parameter (hosted zone id) into a non array.所以我正处于 EC2 调用工作的地步,因为偶然地,我需要一个数组......但我无法弄清楚如何将 Route53 参数(托管区域 ID)转换为非数组。

It was easier than I thought.这比我想象的要容易。 I figure there was an intrinsic that would allow me to extract a value from an array: States.ArrayGetItem .我认为有一个内在函数可以让我从数组中提取一个值: States.ArrayGetItem

The following did the trick:以下是诀窍:

      "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