|
Voiced by Amazon Polly |
Modern cloud applications rarely execute in a single step. Real-world systems involve long-running workflows, retries, branching logic, human approvals, and AI inference chains. Managing these reliably using plain AWS Lambda can quickly become complex.
This is where durable, stateful workflows come into play.
In this blog, we’ll explore how to build multi-step applications and AI workflows using AWS Lambda with durable orchestration, primarily leveraging AWS Step Functions as the durability layer to simplify complex workflows.
Start Learning In-Demand Tech Skills with Expert-Led Training
- Industry-Authorized Curriculum
- Expert-led Training
Why Traditional Lambda Falls Short for Multi-Step Workflows
AWS Lambda is stateless, short-lived (with a maximum execution time of 15 minutes), and event-driven. While these characteristics are powerful and make Lambda highly scalable and efficient, they also introduce challenges when building long-running business processes, multi-step pipelines, AI workflows that require retries and branching, or human-in-the-loop approval systems.
Common problems in such scenarios include managing state across multiple steps, handling errors and retries consistently, dealing with tangled orchestration logic within application code, and difficulty visualizing workflow progress. Although the term “Durable Functions” originates from Azure, the same concept in AWS is implemented using AWS Step Functions in combination with AWS Lambda. Together, these services provide state persistence, checkpointing, automatic retries, and built-in error handling, enabling the creation of resilient and well-orchestrated workflows.
What Are “Durable Functions” in AWS?
The term Durable Functions originates from Azure, but in AWS, the concept is implemented using:
AWS Step Functions + AWS Lambda
The term “Durable Functions” originates from Azure, but in AWS, the same concept is achieved by combining AWS Step Functions with AWS Lambda. Together, these services enable the creation of reliable, long-running workflows by providing built-in state persistence, checkpointing between steps, automatic retries, and robust error handling.
Architecture Diagram:

Use Case: Multi-Step Business Application
Example: Order Processing System
The workflow begins by receiving the customer’s order and capturing all relevant details for processing. Next, the system validates the inventory to ensure that the requested items are available in stock. Once availability is confirmed, the payment is processed securely.
After successful payment processing, an invoice is generated to document the transaction. Finally, a confirmation email is sent to the customer, summarizing the order details and confirming that the purchase was successful.
Step Functions Benefits
In this workflow, if the payment process fails, the system automatically retries the transaction according to predefined retry policies, reducing the need for manual intervention. If the inventory is unavailable, the workflow branches to compensation logic, which may include notifying the customer, cancelling the order, or triggering alternative fulfilment steps.
Additionally, each step in the workflow can be scaled independently, allowing the system to handle varying loads efficiently and ensuring high performance and resilience throughout the process.
Step-by-Step AWS Implementation
Step 1: Receive Order
Amazon API Gateway, AWS Lambda, and Amazon DynamoDB work together to handle order processing. When a client submits an order through a REST API, API Gateway receives the request and triggers the ReceiveOrder Lambda function. The Lambda function validates the incoming request payload to ensure it meets the required format and business rules, and then generates a unique orderId for tracking. It stores the order details in the DynamoDB Orders table with an initial status of RECEIVED.
After successfully saving the order, the Lambda function initiates the corresponding AWS Step Functions workflow execution to continue processing the order.
Sample Order Table (DynamoDB)
|
1 2 3 4 5 6 7 8 9 10 11 |
{ "orderId": "ORD123", "status": "RECEIVED", "items": [...], "totalAmount": 2500 } |
Step 2: Validate Inventory
In this stage of the workflow, AWS Lambda and Amazon DynamoDB are used to validate and manage inventory. AWS Step Functions invokes the ValidateInventory Lambda function, which checks the Inventory table in DynamoDB to verify stock availability for the requested items. If the items are in stock, the Lambda function reserves the required inventory and updates the order status to INVENTORY_CONFIRMED.
For failure handling, if the stock is unavailable, Step Functions transitions the workflow to a Fail or Compensation state. In this case, the order is marked as OUT_OF_STOCK, and the customer is notified accordingly, ensuring clear communication and proper handling of the situation.
Step 3: Process Payment
AWS Services
- Lambda: ProcessPayment
- External Payment Gateway
- AWS Secrets Manager (API keys)
In this step of the workflow, the Lambda function calls the external payment provider to process the transaction. If the payment is successful, the order status is updated to PAYMENT_SUCCESS. However, if the payment attempt fails, AWS Step Functions automatically retries the operation based on the configured retry policy.
If the payment continues to fail even after the maximum number of retry attempts is reached, the workflow transitions to the payment failed path for further handling, such as marking the order accordingly or notifying the customer.
Retry Policy Example
|
1 2 3 4 5 6 7 8 9 10 11 |
"Retry": [{ "ErrorEquals": ["States.ALL"], "IntervalSeconds": 5, "MaxAttempts": 3, "BackoffRate": 2 }] |
Step 4: Generate Invoice
AWS Services
- Lambda: Generate Invoice
- Amazon S3
- Optional: Amazon SES (PDF attachment)
In this step of the workflow, the Lambda function generates an invoice in PDF or JSON format based on the completed order details. The generated invoice is then stored in Amazon S3 for secure and reliable storage. After successfully saving the invoice, the order status is updated to INVOICED. This approach ensures durable invoice storage, making the documents auditable and easily downloadable whenever needed for compliance, record-keeping, or customer access.
Step 5: Send Confirmation Email
AWS Services
- Lambda: Send Notification
- Amazon SNS or SES
In the final step of the workflow, the Lambda function sends an order confirmation to the customer. The confirmation includes key details such as the Order ID, a link to download the invoice, and the delivery information. After the confirmation is successfully sent, the order status is updated to COMPLETED, marking the end of the order processing lifecycle.
AWS Step Functions State Machine (Simplified)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
{ "StartAt": "ReceiveOrder", "States": { "ReceiveOrder": { "Type": "Task", "Resource": "arn:aws:lambda:receive-order", "Next": "ValidateInventory" }, "ValidateInventory": { "Type": "Task", "Resource": "arn:aws:lambda:validate-inventory", "Next": "ProcessPayment" }, "ProcessPayment": { "Type": "Task", "Resource": "arn:aws:lambda:process-payment", "Next": "GenerateInvoice" }, "GenerateInvoice": { "Type": "Task", "Resource": "arn:aws:lambda:generate-invoice", "Next": "SendEmail" }, "SendEmail": { "Type": "Task", "Resource": "arn:aws:lambda:send-email", "End": true } } } |
Security Best Practices
- To ensure strong security practices, each Lambda function is configured with IAM roles that follow the principle of least privilege, granting only the permissions necessary to perform its specific tasks. Sensitive information, such as API keys and credentials, is securely stored in AWS Secrets Manager to avoid hardcoding secrets in the application code.
- Amazon API Gateway is protected using AWS WAF to guard against common web exploits and malicious traffic. Additionally, encryption at rest is enabled for services like DynamoDB and Amazon S3 to protect stored data and ensure compliance with security and regulatory requirements.
Conclusion
AWS Lambda combined with Durable Functions makes it easier to build reliable, multi-step applications and AI workflows without managing infrastructure. By handling state, retries, and orchestration for you, this approach lets developers focus on business logic while scaling seamlessly. As workflows grow more complex, especially in AI-driven systems, this pattern provides a clean, flexible foundation for building resilient serverless applications.
Upskill Your Teams with Enterprise-Ready Tech Training Programs
- Team-wide Customizable Programs
- Measurable Business Outcomes
About CloudThat
CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.
WRITTEN BY Siddhartha Rajbhatt
Login

March 18, 2026
PREV
Comments