Introduction to AWS Step Functions

What is AWS Step Functions?

AWS Step Functions is an AWS service that choreographs executions; all you do is build the flow of those executions. Those execution flows are built with a DSL language called Amazon State language (ASL). Using ASL you build an execution flow by connecting States to each other. If you want to achieve parallelism you would add branches to your execution flow. Before going on a tangent, here is a list of States that are available for you to use when building your execution flow :

Hello World

Let's build a hello world State Machine to see how AWS Step Functions works. While we're at it, let's also add branch logic to see how parallelism can be achieved. The final State Machine flow will execute 3 lambdas. 2 lambdas will be executed on one branch and the 3rd lambda will be executed on the other.

Create Lambdas

Keeping things simple for this introduction, create 3 default Hello World lambdas called test1, test2, and test3. (click here)

Make sure to note their ARN names. The ARN name is a long string on the config page that looks similar to this (arn:aws:lambda:us-east-1:171566796811:function:test1). Those names are used as references to tell the State Machine what lambda to execute within a Step.

For each lambda, you may want to click edit inline and change the callback to respond an object or variable. This step is useful for educational purposes when inspecting the State Machines execution logs to see how the data is being passed around from one lambda to another. Typically, this would contain the results of some application business logic.

Create State Machine

Navigate AWS Step Functions (click here) and create a State Machine.
Name your State Machine and select Parallel blue print.

Update the blueprint to look similar to the following :

{
    "Comment": "Hello State Machine",
    "StartAt": "Parallel",
    "States": {
        "Parallel": {
            "Type": "Parallel",
            "Next": "Final State",
            "Branches": [{
                    "StartAt": "Wait 20s",
                    "States": {
                        "Wait 20s": {
                            "Type": "Wait",
                            "Seconds": 20,
                            "Next": "test1"
                        },
                        "test1": {
                            "Type": "Task",
                            "Resource": "arn:aws:lambda:us-east-1:171566796811:function:test1",
                            "Next": "test3"
                        },
                        "test3": {
                            "Type": "Task",
                            "Resource": "arn:aws:lambda:us-east-1:171566796811:function:test3",
                            "End": true
                        },
                    }
                },
                {
                    "StartAt": "Pass",
                    "States": {
                        "Pass": {
                            "Type": "Pass",
                            "Next": "Wait 10s"
                        },
                        "Wait 10s": {
                            "Type": "Wait",
                            "Seconds": 10,
                            "Next": "test2"
                        },
                        "test2": {
                            "Type": "Task",
                            "Resource": "arn:aws:lambda:us-east-1:171566796811:function:test2",
                            "End": true
                        }
                    }
                }
            ]
        },
        "Final State": {
            "Type": "Pass",
            "End": true
        }
    }
}

Make sure to change the Resource parameter in the States to your own lambda ARN names.

Execute a Run

Click save and then click on execute run. AWS Step Functions will start executing your flow. If some step fails, there will be a red circle in the execution flow identifying the failed step.