Creating an Order Processing System with Lambda Durable Functions - Amazon Lambda
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Creating an Order Processing System with Lambda Durable Functions

Note

NEED: Add architecture diagram showing API Gateway, Durable Function workflow, and supporting services (DynamoDB, EventBridge)

Prerequisites

  • Amazon CLI installed and configured

  • NEED: Specific Durable Functions requirements

Create the Source Code Files

Create the following files in your project directory:

  • lambda_function.py - the function code

  • requirements.txt - dependencies manifest

Function Code

# NEED: Verify correct imports import boto3 import json def lambda_handler(event, context): # NEED: Verify DurableContext syntax durable = context.durable try: # Validate and store order order = await durable.step('validate', async () => { return validate_order(event['order']) }) # Process payment # NEED: Verify wait syntax await durable.wait(/* wait configuration */) # Additional steps # NEED: Complete implementation except Exception as e: # NEED: Error handling patterns raise e def validate_order(order_data): # NEED: Implementation pass

Requirements File

# NEED: List of required packages

Deploy the App

Create a DynamoDB Table for Orders

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/

  2. Choose Create table

  3. For Table name, enter Orders

  4. For Partition key, enter orderId

  5. Leave other settings as default

  6. Choose Create table

Create the Lambda Function

  1. Open the Lambda console at https://console.aws.amazon.com/lambda/

  2. Choose Create function

  3. Select Author from scratch

  4. For Function name, enter ProcessOrder

  5. For Runtime, choose your preferred runtime

  6. NEED: Add Durable Functions-specific configuration

  7. Choose Create function

Create the API Gateway Endpoint

  1. Open the API Gateway console at https://console.aws.amazon.com/apigateway/

  2. Choose Create API

  3. Select HTTP API

  4. Choose Build

  5. Add an integration with your Lambda function

  6. Configure routes for order processing

  7. Deploy the API

Test the App

Submit a test order:

{ "orderId": "12345", "items": [ { "productId": "ABC123", "quantity": 1 } ] }

NEED: Add specific monitoring instructions for Durable Functions

Next Steps

Add Business Logic

Implement inventory management:

async def check_inventory(order): # Add inventory check logic pass

Add price calculations:

async def calculate_total(order): # Add pricing logic pass

Improve Error Handling

Add compensation logic:

async def reverse_payment(order): # Add payment reversal logic pass

Handle order cancellations:

async def cancel_order(order): # Add cancellation logic pass

Integrate External Systems

async def notify_shipping_provider(order): # Add shipping integration pass async def send_customer_notification(order): # Add notification logic pass

Enhance Monitoring

  • Create CloudWatch dashboards

  • Set up metrics for order processing times

  • Configure alerts for delayed orders