我有一个状态机,它有一个映射状态,遍历一个由2个元素组成的数组,其输出如下:
[
{
"BillingDetails": {
"BilledDurationInMilliseconds": 100,
"BilledMemoryUsedInMB": 64
},
"ExecutionArn": "arn:aws:states:us-west-2:693935722839:express:restaurantdbread:53054495-6e74-47bb-b58e-ad1f40b8282e:255e2717-5126-422a-81e4-b13e505a2f16",
"Input": "{\"restaurant_name\":\"outback\"}",
"InputDetails": {
"Included": true
},
"Name": "53054495-6e74-47bb-b58e-ad1f40b8282e",
"Output": "\"27\"",
"OutputDetails": {
"Included": true
},
"StartDate": "2022-11-17T08:47:30.364Z",
"StateMachineArn": "arn:aws:states:us-west-2:693935722839:stateMachine:restaurantdbread",
"Status": "SUCCEEDED",
"StopDate": "2022-11-17T08:47:30.435Z"
},
{
"BillingDetails": {
"BilledDurationInMilliseconds": 100,
"BilledMemoryUsedInMB": 64
},
"ExecutionArn": "arn:aws:states:us-west-2:693935722839:express:restaurantdbread:7d1597ea-973a-41ac-bf16-f506dd745566:f72ecfc1-93fc-47aa-a494-e925f9c95214",
"Input": "{\"restaurant_name\":\"ihop\"}",
"InputDetails": {
"Included": true
},
"Name": "7d1597ea-973a-41ac-bf16-f506dd745566",
"Output": "\"0\"",
"OutputDetails": {
"Included": true
},
"StartDate": "2022-11-17T08:47:30.366Z",
"StateMachineArn": "arn:aws:states:us-west-2:693935722839:stateMachine:restaurantdbread",
"Status": "SUCCEEDED",
"StopDate": "2022-11-17T08:47:30.437Z"
}
]
我需要编写一个如下所示的输出:
[{"name": "outback", "value": 27}, {"name": "chipotle", "value": 0}]
将以下ResultSelector
添加到我的状态机
"ResultSelector": {
"name.$": "States.StringToJson($.Input)",
"value.$": "States.StringToJson($.Output)"
},
现在我得到了接近我所需要的东西:
[
{
"name": {
"restaurant_name": "outback"
},
"value": "27"
},
{
"name": {
"restaurant_name": "ihop"
},
"value": "0"
}
]
我正在努力调整输出,以便"restaurant_name":get被丢弃以实现所需的格式。
我试图调整ResultSelector
以使用:
"ResultSelector": {
"name.$": "States.StringToJson($.Input.restaurant_name)",
"value.$": "States.StringToJson($.Output)"
},
但是工作流吐出了这个错误:
The function 'States.StringToJson($.Input.restaurant_name)' had the following error: The JsonPath argument for the field '$.Input.restaurant_name' could not be found in the input '{"BillingDetails":{"BilledDurationInMilliseconds":100,"BilledMemoryUsedInMB":64},"ExecutionArn":"arn:aws:states:us-west-2:693935722839:express:restaurantdbread:b8e9de51-1806-47ab-b4e6-1c60d6cd9fc1:9ce2cb9d-0b57-4066-b7de-a41668d6113f","Input":"{\"restaurant_name\":\"ihop\"}","InputDetails":{"Included":true},"Name":"b8e9de51-1806-47ab-b4e6-1c60d6cd9fc1","Output":"\"0\"","OutputDetails":{"Included":true},"StartDate":"2022-11-17T08:58:44.627Z","StateMachineArn":"arn:aws:states:us-west-2:693935722839:stateMachine:restaurantdbread","Status":"SUCCEEDED","StopDate":"2022-11-17T08:58:44.686Z"}'
对于只提取餐厅名称的语法有什么建议吗?
发布于 2022-11-18 05:13:09
我能够通过添加一个新的map
状态来解决(或解决)我的问题,该状态分解输入中的数组并将Parameters
应用于Pass
任务。这是附加状态的样子:
"Map formatting": {
"Type": "Map",
"End": true,
"Iterator": {
"StartAt": "Pass",
"States": {
"Pass": {
"Type": "Pass",
"End": true,
"Parameters": {
"name.$": "$.name.restaurant_name",
"value.$": "$.value"
}
}
}
}
}
这可能不是实现我所需的最有效的方法(我可能不需要两个单独的映射来构造所需的输出),但现在我更关注的是工作的基本功能,而不是一个优化的工作流,所以它适合我。
https://stackoverflow.com/questions/74478604
复制