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"
}
CodePudding user response:
TL;DR Use the parameters
arg instead of result
.
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.
second_pass = aws_stepfunctions.Pass(
self,
"second_pass",
parameters={
"iterator": {"count": 5, "index": 0, "step": 1, "continue": True},
"globals": aws_stepfunctions.JsonPath.string_at("$.globals"),
},
)
CodePudding user response:
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 to second_pass
.
Like thiss:
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": {},
},
}
)
)
globals = initial_pass.result["globals"]
second_pass = aws_stepfunctions.Pass(
self,
"second_pass",
result=aws_stepfunctions.Result.from_object(
{
"iterator": {"count": 5, "index": 0, "step": 1, "continue": True},
"globals": globals,
}
),
)
Edit:
It seems that the result
attribute is not supported in the Pass
state of AWS Step Functions.
As a workaround, you could pass the result of the initial_pass
state as input to the second_pass
state, and then extract the required fields using JsonPath.
Delete the line:
globals = initial_pass.result["globals"]
Replace second_pass
with:
second_pass = aws_stepfunctions.Pass(
self,
"second_pass",
input_path=aws_stepfunctions.JsonPath.string_at("$.result"),
result=aws_stepfunctions.Result.from_object(
{
"iterator": {"count": 5, "index": 0, "step": 1, "continue": True},
"globals": aws_stepfunctions.JsonPath.string_at("$.globals"),
}
),
)