- Newest
- Most votes
- Most comments
The error message "RuntimeError: Cannot read properties of undefined" is typically encountered when trying to access a property or method of a variable that has not been defined. In order to resolve this issue, you can add the @property decorator above the start_state and end_states methods, this will ensure that the methods are treated as properties and can be accessed without encountering the undefined error.
The second error message "AttributeError: can't set attribute" occurred because you had defined methods and attributes with the same name, namely "start_state" and "end_states". In Python, methods are attributes too, and having an attribute and method with the same name can cause naming conflicts. To fix this issue, you can simply rename the attributes to something else, you could use "_start_state" and "_end_states".
You can find both fixes below, these changes will ensure that your code runs smoothly:
from aws_cdk import (
# Duration,
Stack,
aws_stepfunctions as sfn,
aws_stepfunctions_tasks as tasks,
)
from constructs import Construct
class MyJob(sfn.StateMachineFragment):
def __init__(self, parent, id, *, job_flavor):
super().__init__(parent, id)
choice = sfn.Choice(self, "Choice").when(sfn.Condition.string_equals("$.branch", "left"), sfn.Pass(self, "Left Branch")).when(sfn.Condition.string_equals("$.branch", "right"), sfn.Pass(self, "Right Branch"))
# ...
self._start_state = choice
self._end_states = choice.afterwards().end_states
@property
def start_state(self):
return self._start_state
@property
def end_states(self):
return self._end_states
class CdkStateMachineFragmentStack(Stack):
def __init__(self, scope, id):
super().__init__(scope, id)
# Do 3 different variants of MyJob in parallel
parallel = sfn.Parallel(self, "All jobs").branch(MyJob(self, "Quick", job_flavor="quick").prefix_states()).branch(MyJob(self, "Medium", job_flavor="medium").prefix_states()).branch(MyJob(self, "Slow", job_flavor="slow").prefix_states())
sfn.StateMachine(self, "MyStateMachineFragmentTest",
definition=parallel
)
Relevant content
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 4 months ago