我有一个参数"request_id",我想从两种不同格式的JSON中获得一个id,这两种格式被发送到我的步骤函数任务的输入端。
第一种形式如下:
{ "request_id": "abcde-abcd-abcde-abc" }
第二种是这种形式:
{ "request": { "id": "abcde-abcd-abcde-abc", }
目前,我有一个看起来像的参数
"request_id.$": "$.request_id"
但想要与等效的东西(这个不起作用(
"request_id.$": "$.['request_id','request.id']"
这在step函数中可能吗?或者我需要在JSON中将这两个请求id拆分为两个路径,还是在函数中进行?
一种解决方法是选择状态并检查是否存在第一个变量:
{
"Variable": "$.request_id",
"IsPresent": true
}
然后根据结果进行两种不同的分配。
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html
{
"StartAt": "choice",
"States": {
"choice": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.request_id",
"IsPresent": true,
"Next": "assignment1"
}
],
"Default": "assignment2"
},
"assignment1": {
"Type": "Pass",
"Result": "World",
"End": true
},
"assignment2": {
"Type": "Pass",
"Result": "World",
"End": true
}
}
}