简体   繁体   English

如何使用 JSONPath 创建 JSON object 供 AWS Step Functions 使用?

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

相关问题 如何在 AWS Cloudwatch 自定义事件中使用 JSON 逻辑? - How can I use JSON logic in an AWS Cloudwatch custom event? 在 AWS Step Functions Catch 方法的下游步骤中使用 output 变量 - Use output variable in downstream step on AWS Step Functions Catch method 在 AWS Step Functions 中使用动态密钥生成 JSON object - Generating JSON object with dynamic keys in AWS Step Functions 使用 JSON 输入替换 AWS Step Function 中的“变量” - Use JSON Input to Replace 'Variable' in AWS Step Function 如何使用 AWS Step Functions 访问之前的 state 输入? - How can I access preceding state inputs using AWS Step Functions? 如何在 AWS Step Functions 中获取要传递到下一步的变量? - How do I get a variable to be passed across into the next Step, in AWS Step Functions? 从 CDK 中的 JSON 文件创建 Step Functions - Create Step Functions from JSON File in CDK 如何将 Firebase 参数化配置与 Typescript 一起用于 Cloud Functions? - How can I use Firebase Parameterized configuration with Typescript for Cloud Functions? 如何将 AWS EBS 卷与裸机 Kube.netes 一起使用 - How can I use AWS EBS Volumes with bare metal Kubernetes 在 CDK ShellStep(管道)步骤中使用 AWS CLI - Use the AWS CLI in a CDK ShellStep (pipeline) step
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM