In this article , We are going to learn how to create a step functions state machines , add a definition for the state machine and execute them.
What is Step Function?
Step functions uses the components of distributed applications as a series of steps in a visual workflow.
It helps to coordinate multiple AWS services into serverless workflow So that we can build and update applications quickly.
Using Step functions State Machines we can design the workflow by merging the multiple AWS services.
How Step Function Works?
- We should define the steps of the workflow in JSON format , Which means we have to add a JSON code as a definition for the state machine.
- Then we need to execute the definitions to see the workflow in visual format and we can verify whether all the steps of applications are in order as expected.
- Step functions operates and scales the steps of the application and the underlying compute resources , To ensure that the applications run reliably on demands.
Use Cases of Step Functions:
- Step function is used to Invoke Lambda Function by calling the Lambda Invoke API.
- To Invoke SNS for publishing message to the subscribers.
- It invokes Batch jobs , Send messages to SQS queue.
- Helps to manage tasks in ECS.
- To create , delete and manage EMR clusters.
- Manages DynamoDB by calling GET,PUT,DELETEand UPDATE API.
- Starts the job of AWS Glue.
States of Step Function:
In step function, States makes the decision based on the input , perform other actions and pass the output to other states.
- Task – Runs some task in state machine
- Pass – Passes the input to the output
- Choice – Makes choices between branches of executions
- Wait – Delay for some time before execution
- Fail or Success – Stops an execution with fail or success state
- Parallel – Run parallel branches of execution
Creating step functions:
Lets go ahead and create a step functions state machines,
Login to STEP FUNCTION CONSOLE
Click Get started ,
Click State machines, You should see the following page ,
Choose Create state machine
We need to Definite the State machine , Which means we have to pass the definitions in the JSON format for the state machine to build a visual workflow.
AWS provides a sample templates.
For this tutorial ,Lets Start with a template
Choose Hello world template,
Under Type , Choose Standard
Based on the Template , You can find the definition for the state Machine and the Visual Workflow created as per the JSON code.
Click Next , We have to attach an IAM role with the proper permission based on which service step function is invoking.
Under Permission , Choose Create new role
You can tag the Step functions and click Create state machine.
Execute the State machine:
Now we have step function state machine in place. Lets execute the state machine ,
On the Hello world page , Click Start Execution
You will see this page, For every new execution of state machine , You will get a execution id by default , Or else you can type a execution name for your identification.
Then Click Start execution.
In the Execution details page , You can see the status of execution , Start and end time of executions.
Click Output section To view the results of the execution.
We have successfully created a state machine and executed it.Thanks for reading this article.
Hope you have liked it, Please do check out my other publications.