December 29, 2020

AWS Step Functions with Examples Part-1

About Us

Jenish Patel

Introducing AWS Step Functions
  • Blog-Detail ArrowStep Functions is a serverless orchestration service that lets you combine AWS Lambda functions and other AWS services to build business-critical applications.
  • Blog-Detail ArrowThrough Step Functions graphical console, you see your application’s workflow as a series of event-driven steps.
  • Blog-Detail ArrowAWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows.
  • Blog-Detail ArrowStep Functions manage the operations and underlying infrastructure for you to ensure your application is available at any scale.
  • Blog-Detail ArrowBuilding applications from individual components that each perform a discrete function lets you scale and change applications quickly. Step Functions is a reliable way to coordinate components and step through the functions of your application.
  • Blog-Detail ArrowWith AWS Step Functions you pay only for the transition from one step of your application workflow to the next, referred to as a state transition. Billing is metered by state transition, regardless of how long each state persists (up to one year). The AWS Step Functions free tier includes 4,000 state transitions each month.
Prerequisites
Before you get started with AWS Step Functions for the first time, complete the prerequisites that are listed below.

Table of Contents

  • Blog-Detail ArrowCreate an AWS account
  • Blog-Detail ArrowCreate an IAM user and group
  • Blog-Detail ArrowCreate an access key for your IAM user
Getting started with AWS Step Functions
In this blog, you learn the basics of working with Step Functions. You sign in to the Step Functions console, where you create a state machine that uses two “Pass” states. You then start a new execution and review the execution details. You then change one of the “Pass” state’s results and view the changes. Finally, you perform a clean-up step, where you delete your state machine. At the end of this tutorial, you'll know how to create, test, debug, and delete a state machine.
  • Blog-Detail ArrowCreate a state machine
  • Blog-Detail ArrowStart an new execution
  • Blog-Detail ArrowUpdate a state machine
  • Blog-Detail ArrowDelete a state machine
Step 1: Create a state machine
A state machine is a graphical representation of your workflow that you can use to examine the individual steps that define it.
To create a state machine from a predefined Hello world template
  1. Blog-Detail ArrowSign in to the Step Functions console.
  2. Blog-Detail ArrowOn the Define a state machine page, choose Start with a template, and then choose Hello world.
  3. Blog-Detail ArrowUnder Type, choose Standard.
  4. Blog-Detail ArrowUnder Definition, review the state machine's workflow.
The state machine has two panes: a code pane and a visual workflow pane. The code pane is where you define the workflow for your application. The visual workflow pane is where Step Functions shows a graph of your workflow as a series of steps.
If the graph doesn't appear in the visual workflow pane, choose the refresh icon in the top left corner.
  1. Blog-Detail ArrowChoose Next.
  2. Blog-Detail ArrowUnder Permissions, select Create a new IAM role.
    When you create a state machine, you select an IAM role that defines which resources the state machine has permission to access during its execution. Choose from the following options:
  3. Blog-Detail ArrowCreate a new IAM role – Select this option when you want Step Functions to create a new IAM role for you based on the definition of your state machine and its configuration details.
  4. Blog-Detail ArrowChoose an existing role – Select this option if you previously created an IAM role for Step Functions and your state machine has the correct permissions.
  5. Blog-Detail ArrowEnter a role ARN – Select this option if you know the ARN details for the IAM role that you want to use for Step Functions.
  6. Blog-Detail ArrowChoose Create state machine.
Step 2: Start an new execution
To start a new execution
  1. Blog-Detail ArrowOn the Helloworld page, choose Start execution.
  2. Blog-Detail ArrowOptional - On the New execution page, in the exection ID field, you can enter a name of your choice.
    Make sure that the execution name doesn’t contain any non-ASCII characters. If you don’t specify your own execution ID, Step Functions generates a unique execution ID for you.
  3. Blog-Detail ArrowOn the New execution page, choose Start execution.
    After you choose Start execution, the Step Functions console directs you to a page that's titled with your execution ID. On this page, you can review the results of your new execution. Under Execution details, you can see your execution ARN and a status to indicate whether your execution succeeded. You can also see the timestamps for when your execution started and ended.
  4. Blog-Detail ArrowTo view the results of your execution, choose Output.
    The output is World.
Step 3: Update a state machine
Change a Pass state's result, and update your state machine for future exceptions. Then view your changes in the visual workflow pane. An exception is an event that disrupts a step in your workflow.
To change a Pass state's result
  1. Blog-Detail ArrowOn the page titled with your execution ID, choose Edit state machine.
  2. Blog-Detail ArrowOn the Edit Helloworld page, in the code pane, update the second Result to World has been updated!
  3. Blog-Detail ArrowChoose Save, and then choose Start execution.
    After you choose Save, the following message appears:"The changes to your state machine may affect which resources it needs to access. To ensure your state machine has the right permissions, you might need to edit the current IAM role, create a new one, or select a different role."This message is standard. Choose Save anyway.
  4. Blog-Detail ArrowOn the New execution page, choose Start Execution again.
  5. Blog-Detail ArrowOn the next page, in the visual workflow pane, examine the individual steps that define your workflow.
  6. Blog-Detail ArrowOptional - To export the graph of your workflow to an SVG or PNG file, choose Export.
  7. Blog-Detail ArrowTo view the results of your execution, in the visual workflow pane, choose World, and then, under Step details, choose Output.
    The output is World has been updated!
Step 4: Delete state machine
In some cases, you might need to delete your state machine and execution role.
If you're done with this tutorial, delete your state machine and the execution role that Step Functions created for you.
To delete your state machine
  1. Blog-Detail ArrowFrom the navigation menu, choose State machines.
  2. Blog-Detail ArrowOn the State machines page, under State machines, select Helloworld, and then choose Delete.
    After you choose Delete, the following message appears:“You are about to delete your state machine. Do you want to proceed?”This message is standard. Choose Delete state machine.A green status bar appears at the top of your screen. The green status bar tells you that your state machine is marked for deletion. Your state machine will be removed when all of its executions stop running.
To delete your execution role
  1. Blog-Detail ArrowOpen the Roles page for IAM.
  2. Blog-Detail ArrowChoose the IAM role that Step Functions created for you: StepFunctions-Helloworld-role-EXAMPLE.
  3. Blog-Detail ArrowChoose Delete role.
  4. Blog-Detail ArrowChoose Yes, delete.
    Now that you completed this tutorial, you know how to create, test, debug, and delete a state machine.

Third Rock Techkno is a leading IT services company. We are a top-ranked web, voice and mobile app development company with over 10 years of experience. Client success forms the core of our value system.
We have expertise in the latest technologies including angular, react native, iOs, Android and more. Third Rock Techkno has developed smart, scalable and innovative solutions for clients across a host of industries.
Our team of dedicated developers combine their knowledge and skills to develop and deliver web and mobile apps that boost business and increase output for our clients.

Found this blog useful? Don't forget to share it with your network

Already working together?

Log in to your account and connect with your teammates

Featured Insights

Team up with us to enhance and

achieve your business objectives

LET'S WORK

TLogoGETHER