How to pass parameters from one Pass state to another?
aws_stepfunctions.JsonPath.string_at
is working fine when invoking lambda function (insude aws_stepfunctions.TaskInput.from_object
) but it is not working with Pass state (inside aws_stepfunctions.Result.from_object
I have:
initial_pass = aws_stepfunctions.Pass(
self,
"initial_pass",
result=aws_stepfunctions.Result.from_object(
{
"iterator": {"count": 5, "index": 0, "step": 1, "continue": True},
"globals": {
"start_datetime": "2023-01-01",
"end_datetime": "",
"upload_start_datetime": "",
"upload_end_datetime": "",
"device_details": {},
},
}
)
)
second_pass = aws_stepfunctions.Pass(
self,
"second_pass",
result=aws_stepfunctions.Result.from_object(
{
"iterator": {"count": 5, "index": 0, "step": 1, "continue": True},
"globals": aws_stepfunctions.JsonPath.string_at("$.globals"),
}
),
)
I am getting this as output:
{
"iterator": {
"count": 5,
"index": 0,
"step": 1,
"continue": true
},
"globals": "$.globals"
}
2
Answers
The problem is because the
aws_stepfunctions.JsonPath.string_at
method returns a string, not an actual value of the referenced path.To solve it, try extracting the value of the reference in
initial_pass
and pass it as a parameter tosecond_pass
.Like thiss:
Edit:
It seems that the
result
attribute is not supported in thePass
state of AWS Step Functions.As a workaround, you could pass the result of the
initial_pass
state as input to thesecond_pass
state, and then extract the required fields using JsonPath.Delete the line:
Replace
second_pass
with:TL;DR Use the
parameters
arg instead ofresult
.The Pass State
Result
field only accepts static values. It does not perform JSONPath substitutions and does not support intrinsic functions.The
Parameters
field permits transformations. It overrides the preceding state’s input with new key-value pairs. The values can include JSONPath substitutions and intrinsic functions.