ArielB
ArielB

Reputation: 1274

Is there a way to interpolate OutputPath's JsonPath using state's input in AWS step function?

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?

Upvotes: 0

Views: 1018

Answers (1)

Hammad Akhtar
Hammad Akhtar

Reputation: 327

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.

Upvotes: 1

Related Questions