简体   繁体   English

在步骤 Function 中,如何将标量数组转换为字典数组?

[英]In a Step Function, how do I convert an array of scalars into an array of dictionaries?

Input of the step - How to Modify the input of the step in a step function from this:步骤的输入 - 如何修改步骤 function 中的步骤输入:

{
    "A": "X",
    "B": "Y",
    "C": [
        "Z1",
        "Z2",
        "Z3"
    ]
}

and convert into this并转换成这个

{
    "A": "X",
    "B": "Y",
    "C": [
        {
            "Z": "Z1"
        },
        {
            "Z": "Z2"
        },
        {
            "Z": "Z3"
        }
    ]
}

using ASL or C# CDK.使用 ASL 或 C# CDK。 I tried to convert an array of strings to an array of elements using:我尝试使用以下方法将字符串数组转换为元素数组:

        "Modify Input": {
            "Type": "Pass",
            "Parameters": {
                "A": "$.A",
                "B": "$.B",
                "C": [
                    {
                        "Z": "States.array($.C)"
                    }
                ]
            }

Append .$ to the key name if the value is a JsonPath substitution . Append. .$如果值为JsonPath 替换,则为键名。 Without it, Step Functions treats the value as a string literal.如果没有它,Step Functions 会将值视为字符串文字。 Use the States.ArrayGetItem intrinsic function to pick items at an index:使用States.ArrayGetItem 内在 function在索引处选择项目:

{
  "A.$": "$.A",
  "B.$": "$.B",
  "C": [
    { "Z.$": "States.ArrayGetItem($.C,0)" },
    { "Z.$": "States.ArrayGetItem($.C,1)" },
    { "Z.$": "States.ArrayGetItem($.C,2)" }
  ]
}

The CDK accepts these literal values. CDK 接受这些文字值。 It also provides the optional JsonPath class, which exposes methods for the intrinsic classes and lets you omit the .$ from key names.它还提供了可选的JsonPath class,它公开了内部类的方法并允许您从键名中省略.$ The CDK emits the same State Machine definition output either way.无论哪种方式,CDK 都会发出相同的 State 机器定义 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 AWS 中删除或重命名步骤 function 执行 - how do i delete or rename a step function execution in AWS 如何在我的 Lambda Function 中使用带有回调返回步骤 Function 的 Heartbeat? - How do I use Heartbeat with a Callback Return Step Function in my Lambda Function? 如何将 ARRAY 连接到 COLUMN? - How do I join an ARRAY to a COLUMN? 如何在 Step Function 任务的输入路径中访问字符串化的 JSON? - How Do I Access Stringified JSON In A Step Function Task's Input Path? 我可以将包含字符串化数组的行值转换为 BigQuery 中的数组吗 - Can I convert row value contains of stringified array to array in BigQuery 如何将Firebase object转换成数组 - How To Convert Firebase object into an Array 如何在 Firestore React 中设置文档而不覆盖数组 - How Do I Set Doc Without Overwriting Array In Firestore React 如何从步骤 function 直接调用 CloudWatch? - How can I call directly CloudWatch from a step function? 使用“Pre Token Generation Lambda Trigger Function”时,如何设置“claimsToAddOrOverride”以返回数组而不是字符串 - When using the "Pre Token Generation Lambda Trigger Function", how do I set the "claimsToAddOrOverride" to return an array instead of a string 如何在 Nuxt JS 中将 firebase object 转换为数组 - How to convert firebase object to array in Nuxt JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM