Search code examples
amazon-web-servicesaws-step-functions

Combining `InputPath` and `Parameters` in AWS States Language


The AWS States Language specification describes the role of the InputPath and Parameters fields but does not give an example of the filters being used together.

My understanding is that, if specified, the JSON path given by the InputPath field is applied to the raw input producing the effective input. Then, if specified, the value of the parameters field is applied, modifying the effective input.

Extending the example given in the spec, given the following Task state definition:

"X": {
  "Type": "Task",
  "Resource": "arn:aws:swf:us-east-1:123456789012:task:X",
  "Next": "Y",
  "InputPath": "$.sub",
  "Parameters": {
    "flagged": true,
    "parts": {
      "first.$": "$.vals[0]",
      "last3.$": "$.vals[3:]"
    }
  }
}

then, given the following input:

{
  "flagged": 7,
  "sub" : { 
      "vals": [0, 10, 20, 30, 40, 50]
  }
}

the effective input to the code identified in the Resource field would be:

{
  "flagged": true,
  "parts": {
    "first": 0,
    "last3": [30, 40, 50]
  }
}

Is my interpretation correct?


Solution

  • It is totally correct. Parameters is a Payload Template created to reshape input data to meet the format expectations of tasks, while ResultSelector is doing the same thing but for output data.

    The value of "Parameters" MUST be a Payload Template which is a JSON object, whose input is the result of applying the InputPath to the raw input. If the "Parameters" field is provided, its payload, after the extraction and embedding, becomes the effective input.

    Also sometimes specs could be a bit hard to read, a visual graph might be helpful then

    enter image description here