An Introuction to AWS Step Function

First published in: Medium


A step function is some collections of functions or tasks that you execute step by step. These steps can be called states. The picture given below will make it more clear.

States
States

So, the above picture actually depicts the flow of checking if a number is odd or even. As you can see, given a number, if we want to check whether a number is odd or even, we need to go through some steps. In these steps, we do some tasks, take some decision, and then complete our task by displaying the output. A step function is similar to this. So if we explore the above picture, we can find the following steps.

Step 1
Step 1

1) Take an input N to start the flow.

Step 2
Step 2

2) Check if the given input, N is an even or odd number. We do this by the following steps:

a) First, we take the mod of the number, N, i.e. N%2

b) Then we make the decision based on the result of the N%2

Step 3
Step 3

3) If N%2 is 0, we display that the number is Even number.

Step 4
Step 4

4) if N%2 is not 0 then we display that a number is an Odd number.

So now we know what is steps and what is tasks. Now let’s discuss AWS Step function.


AWS Step function

Let’s imagine that you have a system that consists of many distributed components. These components can be any microservice. For example, let’s imagine that you have a registration system. When a user registers through your system, you want to send him/her a notification or an sms. Look at the following image:

fig. send a user notification after a successful registration
fig. send a user notification after a successful registration

As you can see, these are the steps to implement this subsystem. But to give the user a good experience you don’t want to clog your registration module code with notification code. You want them to be two separate modules. Therefore, when the registration is successful, you return the success response to the response consumer and the separated notification module continues to work when the registration is successful. AWS Step function can help you a lot to make these kinds of distributed independent systems.

From the AWS DOC:

AWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows. You build applications from individual components that each perform a discrete function, or task, allowing you to scale and change applications quickly.

Just like I drew an image above, when you’re working with Step functions and setting up steps, you get a graph image of the steps that define the workflow of your system. Here is another detail from AWS DOC:

Step Functions offers a graphical console to visualize the components of your application as a series of steps. It automatically triggers and tracks each step, and retries when there are errors, so your application executes in order and as expected, every time. Step Functions logs the state of each step, so when things do go wrong, you can diagnose and debug problems quickly.

You can run your tasks in the AWS Cloud, on your servers, or on any system that has access to AWS. Access and use Step Functions by using the Step Functions console, the AWS SDKs, or an HTTP API.

For AWS youtube, you can try this one: AWS Step function

What sort of things you can do it Step functions?

  1. Invoke the AWS Lambda function.
  2. Pass data to the AWS Lambda function.
  3. If you have multiple Lambda functions that do different things and you need to accumulate their result, you can do it with the Step function.
  4. You can send the accumulated response to another service through step function.
  5. You can invoke AWS SNS, AWS SQS from Step function.

If we want to work with a Step Function, we need to know how to define it, right? Now in order to define a Step Function, we’ll have to use a language which is called AWS States Language.

This language is a json type of language.

So in our next tutorial, we’ll try to learn about the AWS States Language.

So… our next tutorial is Amazon States Language: Part-1. See you there!

You can get the whole tutorial series from here: A Journey to the AWS Step Function.