AWS Steps Functions State Machine and Lambda
In this guide I’ll show you how to use Lambda with AWS Function to build powerful serverless workflow.
AWS Steps Function lets you build and update apps quickly. Using Steps Function you can design workflows which are made up of series of steps. Developing with Steps Function is more intuitive as steps are translated into State Diagram which is easy to understand and explain to others. As applications executes, Steps Functions maintains application states. This could allow us to easily tell where our process fails and re-execute if needed.
Let’s start by signing-in to our AWS account.We will create first the Lambda Functions which will be used as the event handler in our Step Function. Both function will accept a Stock Code and will try to get the current price and return the values. You can find the CloudFormation yml file here. You can deploy the CloudFormation template using the following:
[cirros@localhost]# aws cloudformation create-stack — template-body file://lambdaFunction.yml — stack-name lambdaFunction — region us-east-1 — capabilities CAPABILITY_NAMED_IAM
{
“StackId”: “arn:aws:cloudformation:us-east-1:**************:stack/lambdaFunction/bc7b5e20–798e-11ea-9017–0a5cf73de175”
}
[cirros@localhost]#
Under CloudFormation console, you should take note of the ARNs under the Outputs section of the stack (BuyTransactionARN and SellTransactionARN). We will be using both values in our Step Functions code.
Let’s now create our Step Functions. Under the Services search box, search for Step Functions.

Select Step Functions to open Step Functions Console page.

On the left panel, click State machines

A State Machine is a collection of states, the relation of those states and their input and output. Step Function console provides you a graphical representation of your State Machines to help visualize your application logic/flow.
Click Create state machine. On the Define State Machine page, select Author with code snippets. Under Type, choose Standard.

Under the Definition section of the State machine, Step Function console generated the Amazon States Language description of the state machine. The Amazon States Language is a JSON-based structured language.

Replace the sample code with this. Do not forget to update the both [REPLACEME BuyTransactionHandler.Arn] and [REPLACEME SellTransactionHandler.Arn]with the corresponding Lambda Function ARNs from the Outputs section of our Stack.

And click the refresh button to update the visual workflow. You should see the visual workflow updated as follows.

Click Next.
In the next page, give it a name. I’m calling my State machine as StockStateMachine. Under the Permissions section, you can leave the Execution role to Create a new role.

Once done, click Create state machine.

We’ve now created a new State machine. To test, click Start execution button.
In the Input section, replace the content with the following:
{
“TransactionType”: “BUY”,
“Stock”: “DIS”,
“Shares”: 100
}

Click Start execution so we could see how our State machine will process our input.
The State machine page is refreshed after execution and the visual diagram is updated with the flow/how it processed our data. You can click each steps and be able to view the details of the process such as the input data and the resulting output. You can see that it returned the current price of Disney(DIS) as shown in the output section.

In this guide, we managed to successfully integrate Step Functions with Lambda to handle the processing of our input data.