New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(stepfunctions): Problem with Choice
and afterwards()
with loop in state machine
#8680
Comments
hey @edisongustavo - what's the desired state machine flow you're trying to get to. What would be ideal authoring workflow? Would it be possible to share a visual representation / ASL definition of the desired state machine? I want to make sure I understand your readability issue first before I think of suggestions or potential improvement(s) on the CDK side of things. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
I'm struggling with the same issue. Here's a specific use case: dataset_version_creation_definition = (
check_stac_metadata_task.lambda_invoke.next(content_iterator_task.lambda_invoke)
.next(
aws_stepfunctions.Choice( # type: ignore[arg-type]
self, "check_files_checksums_maybe_array"
)
.when(
aws_stepfunctions.Condition.number_equals("$.content.iteration_size", 1),
check_files_checksums_single_task.batch_submit_job,
)
.otherwise(check_files_checksums_array_task.batch_submit_job)
.afterwards()
)
.next(
aws_stepfunctions.Choice(self, "content_iteration_finished")
.when(
aws_stepfunctions.Condition.number_equals("$.content.next_item", -1),
validation_summary_task.lambda_invoke.next(
aws_stepfunctions.Choice( # type: ignore[arg-type]
self, "validation_successful"
)
.when(
aws_stepfunctions.Condition.boolean_equals(
"$.validation.success", True
),
import_dataset_task.lambda_invoke.next(
success_task # type: ignore[arg-type]
),
)
.otherwise(validation_failure_lambda_invoke)
),
)
.otherwise(content_iterator_task.lambda_invoke)
)
) I'd like to write this in a flat structure, like this: dataset_version_creation_definition = (
check_stac_metadata_task.lambda_invoke.next(content_iterator_task.lambda_invoke)
.next(
aws_stepfunctions.Choice( # type: ignore[arg-type]
self, "check_files_checksums_maybe_array"
)
.when(
aws_stepfunctions.Condition.number_equals("$.content.iteration_size", 1),
check_files_checksums_single_task.batch_submit_job,
)
.otherwise(check_files_checksums_array_task.batch_submit_job)
.afterwards()
)
.next(
aws_stepfunctions.Choice(self, "content_iteration_finished")
.when(
aws_stepfunctions.Condition.number_equals("$.content.next_item", -1),
validation_summary_task.lambda_invoke,
)
.otherwise(content_iterator_task.lambda_invoke)
.afterwards()
)
.next(
aws_stepfunctions.Choice(self, "validation_successful") # type: ignore[arg-type]
.when(
aws_stepfunctions.Condition.boolean_equals("$.validation.success", True),
import_dataset_task.lambda_invoke,
)
.otherwise(validation_failure_lambda_invoke)
.afterwards()
)
.next(success_task) # type: ignore[arg-type]
) This puts all the |
I have the same issue as well, any update? I resolved the issue after removing the next state of Choice in the default chain |
Hi there, I have kinda the same use case and issue. @edisongustavo have you found a solution? Since this issue has been closed for a while, I've created this new one. @shivlaks please, find there a more detailed explanation and a visual representation Thanks a lot!! |
❓ General Issue
The Question
I've tried to create a loop in a State Machine and I'm getting the following error:
I have reproduced the problem by modifying the example from the stepfunctions readme (converted to Python):
From what I can see, the problem is that there is a loop together with usage of
afterwards()
:I can make the problem go away by not using
afterwards()
and adding the rest of the transitions inside theCondition
:This is not ideal because it will really hurt the readability of the code defining the state machine because I can't read it "top to bottom", instead I have to read it by inspecting each
Choice
.In my real-life example I will have more loops, so that's important.
Environment
Other information
I found this very similar question but it got closed for staleness.
A longer stack trace:
The text was updated successfully, but these errors were encountered: