Extension: For State

The For state provides a “for” loop, from a starting value to an ending value, incrementing via a defined step.

The For state allows a single branch to be executed multiple times, either sequentially or concurrently. Each execution is supplied the value of the iterator, at a location that can be specified by the IteratorPath argument.

One use case for this class occurs where processing will exceed the maximum execution time for an AWS Lambda (currently 300 seconds), but can be efficiently partitioned. The For state then allows processing to be handled in AWS Lambda rather than having to create and maintain an Activity.

class awssl.ext.For(Name=None, Comment='', InputPath='$', OutputPath='$', NextState=None, EndState=None, ResultPath='$', RetryList=None, CatcherList=None, BranchState=None, BranchRetryList=None, From=0, To=0, Step=1, IteratorPath='$.iteration', ParallelIteration=False)

Models the For extension state.

The For state constructs and executes branches for each iterator value in the range [From, To), incrementing by Step.

The same branch is repeatedly executed, with the iterator value injected into the Input data at the location specified by IteratorPath.

The state supports both retry and catch, so that errors can be handled at the state level. If retries are specified, then all the iterations will be re-executed.

Either:

  • EndState is True and NextState must be None
  • EndState is False and NextState must be a valid instance of a class derived from StateBase.
Parameters:
  • Name (str) – [Required] The name of the state within the branch of the state machine
  • Comment (str) – [Optional] A comment describing the intent of this pass state
  • InputPath (str) – [Optional] Filter on the Input information to be passed to the Pass state. Default is “$”, signifying that all the Input information will be provided
  • OutputPath (str) – [Optional] Filter on the Output information to be returned from the Pass state. Default is “$”, signifying that all the result information will be provided
  • EndState (bool) – [Optional] Flag indicating if this state terminates a branch of the state machine. Defaults to False
  • NextState (instance of class derived from StateBase) – [Optional] Next state to be invoked within this branch. Must not be None unless EndState is True
  • ResultPath (str) – [Optional] JSONPath indicating where results should be added to the Input. Defaults to “$”, indicating results replace the Input entirely.
  • RetryList – [Optional] list of Retrier instances corresponding to error states that cause the entire set of branches to be retried
  • CatcherList – [Optional] list of Catcher instances corresponding to error states that can be caught and handled by further states being executed in the StateMachine.
  • BranchState (StateBase) – [Required] The starting StateBase instance of the branch to be executed on each iteration of the For loop
  • BranchRetryList (list of Retrier) – [Optional] list of Retrier instances corresponding to error states that cause the For loop iteration to be retried. This will occur until the number of retries has been exhausted for this iteration, afterwhich state level Retrier will be triggered if specified
  • From (int or float) – [Required] The starting value of the iteration. Must be an integer or float
  • To (int or float) – [Required] The ending value of the iteration. Must be an integer or float
  • Step – [Required] The incremental value of each iteration. Must be an integer or float, and cannot be zero. Default is 1.
  • IteratorPath (str) – [Required] The JSONPath specifying the injection location for the iterator value into the Input data
  • ParallelIteration (bool) – [Optional] Whether the For branches can be run concurrently or must be executed sequentially. Default is sequential.
Type:

RetryList: list of Retrier

Type:

CatcherList: list of Catcher

clone(NameFormatString='{}')

Returns a clone of this instance, with the clone named per the NameFormatString, to avoid state name clashes.

If this instance is not an end state, then the next state will also be cloned, to establish a complete clone of the branch form this instance onwards.

Parameters:NameFormatString (str) – [Required] The naming template to be applied to generate the name of the new instance.
Returns:For – A new instance of this instance and any other instances in its branch.
get_branch_retry_list()

Returns the list of Retrier instances that will be applied separately to each For branch iteration, allowing failure in one branch iteration during the For loop to be retried without having to re-execute all the branches of the For.

Returns:list of Retrier instances
get_branch_state()

Returns the starting state of the branch to be executed within the For loop.

Returns:StateBase
get_from()

Returns the starting value for the For loop

Returns:int or float
get_iterator_path()

Returns the JSON Path of the injection location, into which the loop iterator value will be added, as the Input data is passed to the branch.

Returns:str
get_parallel_iteration()

Returns whether the For loop will execute concurrently or sequentially.

Returns:bool
get_step()

Returns the increment value for the For loop

Returns:int or float
get_to()

Returns the ending value for the For loop

Returns:int or float
set_branch_retry_list(BranchRetryList=None)

Sets the list of Retrier instance to be applied to each of the branch iterations in the For.

If none are specified, then For will retry at the state level (if Retrier are specified)

Parameters:BranchRetryList – [Optional] list of Retrier instances corresponding to error states that can be retried for each branch iteration
Type:BranchRetryList: list of StateBase
set_branch_state(BranchState=None)

Sets the starting state of the branch to be executed within the For loop.

Parameters:BranchState (StateBase) – [Required] The starting StateBase instance of the branch to be executed on each iteration of the For loop
set_from(From=0)

Sets the starting value for the For loop. Must be an integer or float. Default value is zero.

Parameters:From (int or float) – [Required] The starting value of the iteration.
set_iterator_path(IteratorPath='$.iteration')

Sets the JSON Path of the injection location, into which the loop iterator value will be added, as the Input data is passed to the branch.

Parameters:IteratorPath (str) – [Required] The JSONPath specifying the injection location for the iterator value into the Input data
set_parallel_iteration(ParallelIteration=False)

Specifies whether the execution of the For loop can be performed concurrently, or must be sequential. Default is sequential.

Parameters:ParallelIteration (bool) – [Optional] Whether the For branches can be run concurrently or must be executed sequentially.
set_step(Step=1)

Sets the increment value for the For loop. Must be an integer or float. Default value is 1.

Parameters:Step (int or float) – [Required] The increment value of the iteration.
set_to(To=0)

Sets the ending value for the For loop. Must be an integer or float. Default value is zero.

Parameters:To (int or float) – [Required] The ending value of the iteration.
to_json()

Returns the JSON representation of this instance.

Returns:dict – The JSON representation
validate()

Validates this instance is correctly specified.

Raises Exception with details of the error, if the state is incorrectly defined.