Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

using ResultSelector in Map / Iterator in AWS step function : $.variable name is taken literally

I'd like to filter output from each iteration of a Map step before collecting it into an array. However, when I use ResultSelector for this purpose, I am getting a verbatim result instead of content of the variable.

Each lambda in CallWorkerLambda returns a dictionary with element "output". I would like to take only this element (if I don't the IO pipeline gets overwhelmed with service parts of the returned message). To this end, I use "ResultSelector": "$.output" within the Iterator, and then "ResultPath": "$.output_array" in the outer Map step.

However, what I get as the resulting array looks like "output_array": ["$.output", "$.output", "$.output", ... ]

Below is the step code:

"ProcessPatch": {
      "Type": "Map",
      "Next": "Aggregate",
      "InputPath": "$",
      "ItemsPath": "$.taskdef",
      "MaxConcurrency": 0,
      "ResultPath": "$.output_array",
      "Parameters": {
        "Payload.$": "$$.Map.Item.Value",
        "algo_lambda.$": "$.staticdata.algo_lambda",
        "staticdata.$": "$.staticdata"
      },
      "OutputPath": "$",
      "Iterator": {
        "StartAt": "CallWorkerLambda",
        "States": {
          "CallWorkerLambda": {
            "Type": "Task",
            "Resource": "arn:aws:states:::lambda:invoke",
            "Parameters": {
              "FunctionName.$": "$.algo_lambda",
              "Payload": {
                "s.$": "$.Payload",
                "staticdata.$": "$.staticdata"
              }
            },
            "ResultSelector": "$.output",
            "End": true
          }
        }
      }
    }

Any ideas on what makes it fail to recognize $.variables and how to work around it?

question from:https://stackoverflow.com/questions/65840362/using-resultselector-in-map-iterator-in-aws-step-function-variable-name-is

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The ResultSelector field lets you create a collection of key value pairs, where the values are static or selected from the state's result. So ResultSelector should be used like this:

"ResultSelector": {
    "ClusterId.$": "$.output.ClusterId",
    "ResourceType.$": "$.resourceType"
  },

But in your example it lacks key value pairs:

"ResultSelector": "$.output"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...