Introduction
AWS Step Functions lets you orchestrate complex workflows by connecting multiple AWS services without writing coordination code. This visual approach reduces errors and simplifies debugging of serverless processes. In 2026, it remains the go-to solution for reliable event-driven architectures. You will learn to define a simple state machine, integrate it with Lambda, and deploy it using the CLI. This tutorial provides fully functional, copy-ready examples.
Prerequisites
- AWS account with sufficient IAM permissions
- AWS CLI installed and configured
- Basic knowledge of JSON and Python
- Node.js or Python 3.11+ for Lambda functions
Create a Basic Lambda Function
import json
def lambda_handler(event, context):
order_id = event.get('order_id', 'unknown')
print(f'Traitement de la commande {order_id}')
return {
'statusCode': 200,
'body': json.dumps({'message': 'Commande traitée', 'order_id': order_id})
}This simple Lambda function simulates order processing. It receives a JSON event and returns a result. It will serve as the first step in our Step Functions state machine.
Define the Simple State Machine
{
"Comment": "Workflow simple de traitement de commande",
"StartAt": "ProcessOrder",
"States": {
"ProcessOrder": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:123456789012:function:ProcessOrderLambda",
"End": true
}
}
}This JSON file defines a minimal state machine with a single Task state that invokes our Lambda function. The Resource field contains the ARN of the Lambda function to execute.
Add a Validation Step
{
"Comment": "Workflow avec validation",
"StartAt": "ValidateInput",
"States": {
"ValidateInput": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:123456789012:function:ValidateLambda",
"Next": "ProcessOrder"
},
"ProcessOrder": {
"Type": "Task",
"Resource": "arn:aws:lambda:eu-west-1:123456789012:function:ProcessOrderLambda",
"End": true
}
}
}We add a validation step before processing. The Next field chains states sequentially, making the workflow more robust.
Deploy with AWS CLI
#!/bin/bash
aws stepfunctions create-state-machine \
--name OrderProcessingWorkflow \
--definition file://state-machine-v2.json \
--role-arn arn:aws:iam::123456789012:role/StepFunctionsRoleThis CLI command creates the state machine in your AWS account. Ensure the IAM role has permissions to invoke the Lambda functions.
Execute the State Machine
#!/bin/bash
aws stepfunctions start-execution \
--state-machine-arn arn:aws:states:eu-west-1:123456789012:stateMachine:OrderProcessingWorkflow \
--input '{"order_id": "ORD-12345"}'This command starts an execution with input data. You can monitor progress directly from the AWS Step Functions console.
Best Practices
- Always version your state machine definitions
- Use descriptive names for each state
- Configure appropriate timeouts on tasks
- Enable CloudWatch logging for debugging
- Separate dev and prod environments with distinct stacks
Common Mistakes to Avoid
- Forgetting IAM permissions between Step Functions and Lambda
- Hardcoding ARNs without parameterization
- Neglecting error handling with Catch and Retry
- Creating infinite loops without a clear exit state
Go Further
Explore our complete serverless architecture and AWS training at Learni Group.