[英]How can I use JSONPath to create a JSON object for use by AWS Step Functions?
Using an AWS step function, I'm attempting to select only certain data from the results of a task.使用 AWS 步骤 function,我试图 select 仅来自任务结果的某些数据。 For some unfathomable reason, AWS have chosen not to allow Query
in step functions, so I'm using ResultsSelector
.出于某些深不可测的原因,AWS 选择不允许在步骤函数中Query
,所以我使用ResultsSelector
。 However, I'm struggling with the JSONPath that is required.但是,我正在努力处理所需的 JSONPath。
How can I use the ResultsSelector
to construct my desired JSON object?我如何使用ResultsSelector
构造我想要的 JSON object?
Take this result -拿这个结果 -
{
"IsTruncated": false,
"KeyMarker": "",
"MaxKeys": 1000,
"Name": "some-bucket-name",
"Prefix": "some/prefix/",
"VersionIdMarker": "",
"Versions": [
{
"ETag": "\"02e9c20b7cd36fcf6e47926c26f0b39e\"",
"IsLatest": true,
"Key": "some/prefix/my.file",
"LastModified": "2021-09-30T15:34:59Z",
"Owner": {
"Id": "1fd170056d1480a7c1c9b43f5bf0603d91cbabc4ec77eefdcaa10218c3a920f6"
},
"Size": 69606,
"StorageClass": "STANDARD",
"VersionId": "y6XzRsCUZcXMPHqwwnhAGLwTlmPoj9dj"
},
{
"ETag": "\"01bc5b65afe6b0cc0722fc5da32a8a44\"",
"IsLatest": false,
"Key": "some/prefix/my.file",
"LastModified": "2021-09-30T15:34:21Z",
"Owner": {
"Id": "1fd170056d1480a7c1c9b43f5bf0603d91cbabc4ec77eefdcaa10218c3a920f6"
},
"Size": 69407,
"StorageClass": "STANDARD",
"VersionId": "jPdKeUqnYlf0_eNXzHaYCvDfdHLOvRX7"
}
]
}
What I'd like is to use the ResultsSelector
to construct this JSON object -我想要的是使用ResultsSelector
来构建这个 JSON object -
{
"Objects": [
{
"Key": "some/prefix/my.file",
"VersionId": "y6XzRsCUZcXMPHqwwnhAGLwTlmPoj9dj"
},
{
"Key": "some/prefix/my.file",
"VersionId": "jPdKeUqnYlf0_eNXzHaYCvDfdHLOvRX7"
}
]
}
However, the closest I've been able to get so far is by using this -然而,到目前为止我能得到的最接近的是使用这个 -
{
"Key.$": "$.Versions[*].Key",
"VersionId.$": "$.Versions[*].VersionId"
}
Which gets me this -这让我明白了 -
{
"VersionId": [
"y6XzRsCUZcXMPHqwwnhAGLwTlmPoj9dj",
"jPdKeUqnYlf0_eNXzHaYCvDfdHLOvRX7",
],
"Key": [
"some/prefix/my.file",
"some/prefix/my.file"
]
}
The Jayway JsonPath
implementation gives the output with the Key. Jayway JsonPath
实现为 output 提供了密钥。 You need to verify if AWS Step function supports the below jsonpath
.您需要验证 AWS Step function 是否支持以下jsonpath
。
Tool: https://jsonpath.herokuapp.com/工具: https://jsonpath.herokuapp.com/
$.Versions[*].['Key','VersionId']
If it works then you can do something like如果它有效,那么你可以做类似的事情
"Objects.$": "$.Versions[*].['Key','VersionId']",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.