0

Basically, i have the following input:

{
   "name": "abc",
   "choice": "choice1"
}

My dynamoDB table has the following structure:

  1. Partition key - "name"
  2. Complex json with choices:

    {
      "choices": 
      {
         "choice1": ......,
         "choice2": ......
      }    
    }
    

I want to directly read from dynamodb, and get a subitem under the relevant choice:

{
  "StartAt": "Read Next Message from DynamoDB",
  "States": {
        "Read Next Message from DynamoDB": {
      "Type": "Task",
      "Resource": "arn:aws:states:::dynamodb:getItem",
      "Parameters": {
        "TableName": "my_table",
        "Key": {
          "customerName": {"S.$": "$.name"}
        }
      },
      "OutputPath": "$.Item.choices.M.choice1.M.myvalue.S",
      "Next": "World"
    },
    "World": {
      "Type": "Pass",
      "End": true
    }
  }
}

basically i want to do something like "$.Item.choices.M.{$.choice}.M.myvalue.S", and take one of the output's keys from the input. is this possible?

Hammad Akhtar
  • 177
  • 12
ArielB
  • 1,184
  • 2
  • 11
  • 36
  • possible duplication of [Using the Output JSON data returned from a nested Step Function](https://stackoverflow.com/questions/57704695/using-the-output-json-data-returned-from-a-nested-step-function) – Sayuri Mizuguchi Jun 04 '20 at 15:02
  • I don't think so, it talks about json escape, not grabbing the output dynamically – ArielB Jun 05 '20 at 16:46

1 Answers1

1

I think what you're looking for is JsonPath interpolation, but that is not supported as per this thread on AWS forums.

As far as I know Step Functions allow only path reference through $, . and [] operators (Reference Path).

I don't know how much control you have on the DynamoDB table's data but I think your problem can be solved easily if your choice types are modeled in following way

{
  "choices": [{
    "choiceType": "choice1",
    ........
  },
  {
    "choiceType": "choice2",
    ........
  }]
}
  1. Now you can use the map state to iterate over the choices array. Note that don't forget to pass the expected choiceType to each iteration.
  2. First state of the map iterator can be a choice state which compares choiceType and moves to appropriate next state. So, basically your rest of the workflow is modeled as iterator of the map state in step 1.

Now, if you don't have the control over DynamoDB table, then you can process the query result in an AWS Lambda.

Hammad Akhtar
  • 177
  • 12