Order submitted
Customer places an order from the mobile app; the request hits API Gateway as a POST to /orders.
A mobile customer places an order. Instead of making them sit through fulfillment in real time, the request is dropped onto a queue and acknowledged instantly — a second function processes it in the background, and only the outcome comes back around.
Every stage only knows about the one next to it. That's what lets the queue absorb a burst of orders, and what lets a failing message get pulled aside instead of stalling everything behind it.
Customer places an order from the mobile app; the request hits API Gateway as a POST to /orders.
CreateOrder writes the order straight onto Amazon SQS and returns immediately — the customer isn't kept waiting on fulfillment.
ProcessOrder is triggered by the queue one message at a time and does the actual fulfillment work in the background.
Processing succeeds → ProcessOrder publishes to Amazon SNS → the customer gets an email confirming the order.
Processing fails three times → the redrive policy moves the message to the Dead Letter Queue instead of retrying forever.
Every order either reaches the customer as a confirmation, or lands somewhere visible for a human to inspect.
Built entirely from the AWS console, in the order the pipeline depends on itself — the queue exists before anything can send to it, the role exists before the functions that need it.
This is where every incoming order lands before anything touches it.
A second, identical queue that only ever receives messages the pipeline gave up on.
Then, back on order-queue, set its Dead Letter Queue to order-dlq with a maximum receive count.
The channel that carries the "your order went through" notification out to the customer.
Inside the topic, add a subscription and confirm it from the inbox before it will deliver anything.
One execution role, trusted by Lambda, used by both functions in the pipeline.
Accepts the API request and hands it straight to the queue — it does no fulfillment work itself.
A REST API in front of CreateOrder, deployed to a live stage.
Triggered directly by the queue — this is where the actual order handling and notification happen.
Submit an order through the test front end and confirm it comes back around as an email.
CreateOrder only ever writes to the queue. ProcessOrder only ever reads from it and reports the outcome — neither one knows the other exists.
import json import boto3 import os import uuid sqs = boto3.client('sqs') QUEUE_URL = os.environ['QUEUE_URL'] def lambda_handler(event, context): body = json.loads(event['body']) order = { "orderId": str(uuid.uuid4()), "customer": body["customer"], "product": body["product"], "quantity": body["quantity"] } sqs.send_message( QueueUrl=QUEUE_URL, MessageBody=json.dumps(order) ) return { "statusCode": 200, "body": json.dumps({ "message": "Order Created", "order": order }) }
import json import boto3 import os sns = boto3.client('sns') TOPIC = os.environ['SNS_TOPIC_ARN'] def lambda_handler(event, context): for record in event['Records']: order = json.loads(record['body']) print(order) sns.publish( TopicArn=TOPIC, Subject="Order Successful", Message=f""" Order ID: {order['orderId']} Customer: {order['customer']} Product: {order['product']} Quantity: {order['quantity']} """ ) return { "statusCode": 200, "headers": { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Content-Type", "Access-Control-Allow-Methods": "POST,OPTIONS" }, "body": json.dumps({ "orderId": order["orderId"] }) }
order_id outside the loop where it isn't defined — reference order["orderId"] from the last processed record, as shown above, or track it before the loop exits.Submitting the test form returns a 200 immediately — the customer never waits on fulfillment.
The API responds with the generated order ID before ProcessOrder has even run.
Moments later, the subscribed inbox receives the order confirmation published through SNS.