[英]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.