The context object is a powerful new construct for AWS Step Functions. As the name implies it allows you to access contextual information about your state machine and state executions such as the time a state was entered and how many retries have been performed.
Additionally states like Map as well as nested workflows can access special information through the context object. Before we dive into the context object if you need a refresher on AWS Step Functions I recommend the below video.
The special context object properties can be accessed via the Parameters attribute of a given state. Where $ refers to the input JSON of a state $$ refers to the context object. For example the Parameters property below is accessing two of the attributes from the context object.
Below are the properties you can access from the context object, the $$.Task.Token attribute can be used with the callback pattern for asynchronous executions.
- Service Integration Patterns - AWS Step Functions
AWS Step Functions integrates with services directly in the Amazon States Language. You can control these AWS services using three different service integration patterns.
Context Object in the Map State
The Map state exposes the $$.Map.Item.Index and $$.Map.Item.Value of the item associated with the given parallel execution. This allows your parallel executions the ability to determine where in the array of items being processed they are. You could also use a Choice state to make decisions based on the Index of the current execution for example.
- AWS Step Function Map State
AWS Step Functions has released support for dynamic parallelism in the form of the new Map state. This article takes a look at the new state and it's special parameters and properties.
Context Object in Nested Workflows
Although there is no special metadata associated with calling a nested workflow you can use $$.Task.Token to define the AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID variable which can be used to allow the child workflow to know what parent workflow started it. This allows you to much more easily trace executions for debugging and auditing.
- AWS Step Functions Nested Workflows
AWS Step Functions recently added nested workflows, a feature customers have been asking for a lot. In this article we take a look at the new features added for nested workflows.