11.14 Step Functions - A Brief Introduction
Introduction
Here are some of the key features of AWS Step Functions:
Step Functions is based on the concepts of Tasks and State Machines.
You define state machines using the JSON-based Amazon States Language.
The Step Functions console displays a graphical view (Visual Workflow) of your state machine's structure, which provides you with a way to visually check your state machine's logic and monitor executions.
You can:
Creating a State Machine. State machines are defined using JSON text that represents a structure containing the following fields:
Comment (Optional). A human-readable description of the state machine.
StartAt (Required). A string that must exactly match (case-sensitive) the name of one of the state objects.
TimeoutSeconds (Optional). The maximum number of seconds an execution of the state machine may run; if it runs longer than the specified time, then the execution fails with an States.Timeout Error name.
Version (Optional). The version of Amazon States Language used in the state machine, default is "1.0".
States (Required). This field's value is an object containing a comma-delimited set of states. The States field contains a number of States.
When an execution of this state machine is launched, the system begins with the state referenced in the
StartAt
field (Within a state machine, only one state that's designated as the start state). If this state has an"End": true
field, the execution stops and returns a result. Otherwise, the system looks for a"Next": field
and continues with that state next. This process repeats until the system reaches a terminal state (a state with"Type": "Succeed"
,"Type": "Fail"
, or"End": true
), or a run-time error occurs. If your state machine has multiple branches of execution, you may have more than one end state.Starting a New Execution.
Update a State Machine. State machine updates in Step Functions are Eventually Consistent.
Creating a Lambda State Machine Using AWS Step Functions
Creating an IAM Role for Lambda. Lambda requires you to assign an IAM role when you create a Lambda function in the same way Step Functions requires you to assign an IAM role when you create a state machine. You can choose one or more permissions policies to attach to the role.
Creating a Lambda Function. Ensure that your Lambda function is under the same AWS account and region as your state machine.
Testing the Lambda Function.
Creating a State Machine. Use the Step Functions console to create a state machine with a Task state. Add a reference to your Lambda function in the Task state. The Lambda function is invoked when an execution of the state machine reaches the Task state.
On the Create a state machine page, select Author from scratch and enter a Name your state machine.
Create a new or enter an existed IAM role for Step Functions. If you delete the IAM role that Step Functions creates, Step Functions can't recreate it later. Similarly, if you modify the role (for example, by removing Step Functions from the principals in the IAM policy), Step Functions can't restore its original settings later.
In the State machine definition pane, add the state machine definition using the ARN of the Lambda function that you created earlier.
Starting a New Execution. On the LambdaStateMachine page, choose
Start execution
. The New execution page is displayed. It is similar to add a test event for a Lambda Function.
Creating a Lambda State Machine Using AWS CloudFormation
You can use the AWS CloudFormation console and a JSON/YAML template to create the stack (IAM roles, the Lambda function, and the state machine). You will then use the AWS Step Functions console to start the state machine execution.
Choose Create Stack.
On the Select Template page, select Upload a template to Amazon S3.
Give the stack a name, click next until Create the stack.
AWS CloudFormation begins to create the
MyStateMachine
stack and displays theCREATE_IN_PROGRESS
status. When the process is complete, AWS CloudFormation displays theCREATE_COMPLETE
status.To display the resources in your stack, select the stack and choose the
Resources
tab.Starting a State Machine Execution. Log in to the Step Functions console and choose the name of the state machine that you created using AWS CloudFormation. On the MyStateMachine page, choose
Start execution
. The New execution page is displayed. It is similar to add a New Execution for a Lambda State Machine.
Last updated
Was this helpful?