2
votes

What I want in step functions to do is my first step generates an output and in the next step I want that output to be inserted in a json and produced as the output.

For example :

Output for step 1 : HelloWorld

Input for step 2 : HelloWorld

Output for step 2 :

myData : {
 data : HelloWorld
}

I have tried the following state machine, but it fails.

        {
          "Comment": "Sample State Machine",
          "StartAt": "StartTask",
          "States": {
              "StartTask": {
                "Type": "Pass",
                "Result": "Hello World!",
                "Next": "RefactorTask"
            },
            "RefactorTask": {
            "Type": "Pass",
                "Result" : {
                "$" : "$"
            },
            "ResultPath" : "$.myData.data"
        }
    }
}

Error :

 {
  "error": "States.ReferencePathConflict",
  "cause": "Unable to apply step \"myData\" to input \"Hello World!\""
}
1

1 Answers

1
votes

The first state's output is "Hello World".

Meaning that RefactorTask's input is... "Hello World" ! Which is a String, not an object, so it doesn't have any property.

Did you try setting your "ResultPath" directly in StartTaskinstead of adding a Pass State ?

Such as

{
      "Comment": "Sample State Machine",
      "StartAt": "StartTask",
      "States": {
          "StartTask": {
            "Type": "Pass",
            "Result": "Hello World!",
            "ResultPath" : "$.myData.data",
            "Next": "Whatever is your next task"
        }
}

Otherwise you could do it with parallel states... but that would appear to be overkill, wouldn't it ?