Skip to content

StepFunction s3:GetObject's "Add original input to output using ResultPath" output is wrong

0

In the docs it shows:

{
    "product_id": 123,
    "region": "east"
 }

By setting a ResultPath of "$.inventory", you can combine the inventory task result with the original input to produce the following state output:

{
    "product_id": 123,
    "region": "east",
    "inventory" : 400
 }

However I am getting this instead:

{
   "inventory" : {
    "product_id": 123,
    "region": "east"
 }
}

For my case the "$.inventory" variable is an output from a previous step.

asked 2 years ago451 views

2 Answers
0

It appears there may be a misunderstanding about how ResultPath works in AWS Step Functions. The behavior you're experiencing is actually the correct implementation of ResultPath.

When you set ResultPath to "$.inventory", you're instructing Step Functions to place the entire input of the state into a new field called "inventory" in the output. This is why you're seeing the original input nested under the "inventory" key.

If you want to achieve the output structure shown in the documentation example, you would need to do the following:

  1. Use InputPath to pass only the necessary fields to the task (if needed).
  2. Have your task return only the inventory value (400 in this case).
  3. Use ResultPath as "$.inventory" to add this result to the original input.

For example, if your task returns just the number 400, then using ResultPath as "$.inventory" would produce the output you're expecting:

{
"product_id": 123,
"region": "east",
"inventory" : 400
}

If you need to manipulate the task output before combining it with the input, you might need to use a combination of ResultSelector and ResultPath, or consider using a Pass state to reshape the data.

Remember, ResultPath determines where in the input the result of the task execution will be placed. If you want to merge specific fields from the task result with the input, you might need to adjust your task to return only those fields or use more complex JsonPath expressions in your state machine definition.
Sources
Gather Amazon S3 bucket info using AWS SDK service integrations - AWS Step Functions

answered 2 years ago

0
EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.