Voiced by Amazon Polly |
Introduction
AWS Step Functions is a fully-managed AWS service that lets us coordinate distributed microservices and applications using visual workflows. With Step Functions, we can build applications that react to events and execute business logic serverless.
AWS Step Functions provide a way to describe the workflow of your application as a state machine, which is made up of a set of states executed in a specific order. Each state in the state machine performs some specific action or task and can transition to other states based on conditions.
AWS Step Functions also provide a range of features that make it easy to build and manage your workflows, including:
- Visual Workflow Designer: a drag-and-drop interface that lets you create and modify your state machine.
- State Machine Logging and Monitoring: Step Functions provide a complete history of all state transitions, making debugging issues and troubleshooting errors easy.
- Error Handling: Step Functions provide built-in error handling and retries, so you can easily handle errors and recover from failures.
Step Functions also integrate with other AWS services such as Amazon CloudWatch, AWS X-Ray, and AWS EventBridge, providing additional visibility and control over your workflows.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Why must we use AWS Step Function to invoke AWS Lambda with another?
AWS Step Functions are important for calling one Lambda function from another because it provides a powerful and scalable way to orchestrate the flow of your application. While it’s possible to call one AWS Lambda function from another directly, this approach can quickly become complex and difficult to manage as your application grows.
By using AWS Step Functions to orchestrate the flow of your application, you can easily build complex workflows that involve multiple AWS Lambda functions and other AWS services. This provides a scalable and reliable way to manage the flow of your application, ensuring that each Lambda function is executed in the correct order and with the correct inputs and outputs.
AWS Step Functions also provide a range of features that make it easy to manage and monitor your workflows, including visual workflow design, state machine logging and monitoring, and built-in error handling and retries. This makes it easy to troubleshoot issues and ensure your application runs smoothly.
Steps to invoke AWS Lambda with another AWS Lambda by using AWS Step Function
Step 1: Create the first-lambda
Add the following sample code in first-lambda
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import json import boto3 import os account_number = os.environ["acc_num"] statemachine_name = os.environ["state_machine"] aws_region = os.environ["region"] def start_state_machine(state_machine_arn:str, msg:str): client = boto3.client('stepfunctions') response = client.start_execution( stateMachineArn=state_machine_arn, input=msg) return response def lambda_handler(event, context): print(event) print(type(event)) msg = json.dumps(event) print(type(msg)) print(msg) start_state_machine(f"arn:aws:states:{aws_region}:{account_number}:stateMachine:{statemachine_name}",msg) return event |
- Create Environment Variables on first-lambda
- Use the name of the AWS Step function in advance, which you will create in the next steps, and give the region where you are creating the resources.
- Now create an event as the following.
- Add the following policy to the lambda role – AWSStepFunctionFullAccess
Step 2: Create the second-lambda
Add the following sample code
1 2 3 4 |
import json def lambda_handler(event, context): print(event) return event |
- Create a step function.
- Drag and drop the AWS Lambda invocation icon on the left and select the second lambda on the right under the function name.
Note – Don’t select the first-lambda in this step because if you select that, then it will go in an infinite loop which will not stop execution until you stop the execution, so that it might give you cost on the resources.
- Click on next
- Click on Create after giving the name and role for it.
- After the successful execution of the AWS Step function.
- Execution input and output
- The result can be seen in Amazon CloudWatch logs of first-lambda
- The result can be seen in CloudWatch logs of second-lambda
Conclusion
Using AWS Step Functions to orchestrate the flow of your application provides a powerful and scalable way to manage the interaction between AWS Lambda functions and can help to ensure that your application is reliable and easy to maintain.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront Service Delivery Partner, Amazon OpenSearch Service Delivery Partner, AWS DMS Service Delivery Partner, AWS Systems Manager Service Delivery Partner, Amazon RDS Service Delivery Partner, AWS CloudFormation Service Delivery Partner, AWS Config, Amazon EMR and many more.
FAQs
1. Which is better, AWS Lambda calling AWS Lambda or with AWS Step Functions?
ANS: – Calling one AWS Lambda function from another directly can be a simple approach for small-scale applications, where the workflow is relatively simple and easy to manage. However, as the application grows in complexity, this approach can quickly become unwieldy and difficult to maintain, as many AWS Lambda functions may need to be called in a specific order, with specific inputs and outputs.
2. Does AWS Step Function have an additional cost for this process?
ANS: – Yes, using AWS Step Functions does incur an additional cost for your application. AWS Step Functions charges for the number of state transitions and the total duration of your state machine execution. Check for more details on AWS service pricing.

WRITTEN BY Suresh Kumar Reddy
Yerraballi Suresh Kumar Reddy is working as a Research Associate - Data and AI/ML at CloudThat. He is a self-motivated and hard-working Cloud Data Science aspirant who is adept at using analytical tools for analyzing and extracting meaningful insights from data.
Comments