Order Pipeline · Build Sheet
Reference architecture · AWS

Nobody waits on the order.
The queue does the waiting.

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.

Fig. 01 — request & message flowAsync · Decoupled · Retry-safe
Customer mobile app API Gateway POST /orders CreateOrder λ · python3.12 order-queue Amazon SQS ProcessOrder λ · trigger:SQS 3 attempts retry check Amazon SNS order-notification Email sent customer notified Dead Letter Queue order-dlq · max 3 receives
What actually happens

Six handoffs, one decoupled pipeline

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.

01

Order submitted

Customer places an order from the mobile app; the request hits API Gateway as a POST to /orders.

02

Queued, not processed

CreateOrder writes the order straight onto Amazon SQS and returns immediately — the customer isn't kept waiting on fulfillment.

03

Picked up async

ProcessOrder is triggered by the queue one message at a time and does the actual fulfillment work in the background.

04a

Success path

Processing succeeds → ProcessOrder publishes to Amazon SNS → the customer gets an email confirming the order.

04b

Failure path

Processing fails three times → the redrive policy moves the message to the Dead Letter Queue instead of retrying forever.

05

Nothing is lost

Every order either reaches the customer as a confirmation, or lands somewhere visible for a human to inspect.

Build sequence

Nine steps, console-first

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.

01
Create the SQS queue

This is where every incoming order lands before anything touches it.

Name order-queue
Type Standard
Visibility timeout 30 sec
Retention 4 days
SQS queue configuration screen showing order-queue, Standard type, 30 second visibility timeout, 4 day retention
order-queue · configuration
02
Create the Dead Letter Queue

A second, identical queue that only ever receives messages the pipeline gave up on.

Name order-dlq
Type Standard
Visibility timeout 30 sec
Retention 4 days
Dead letter queue order-dlq configuration screen
order-dlq · configuration

Then, back on order-queue, set its Dead Letter Queue to order-dlq with a maximum receive count.

Maximum receives 3
Redrive policy screen setting order-dlq as the dead letter queue for order-queue with maximum receives set to 3
order-queue · redrive policy → order-dlq
If the Lambda consuming a message fails three times, that message moves to the DLQ automatically — no custom retry logic required.
03
Create the SNS topic

The channel that carries the "your order went through" notification out to the customer.

Type Standard
Name order-notification
SNS topic creation screen for order-notification, Standard type
order-notification · topic details
04
Subscribe an email endpoint

Inside the topic, add a subscription and confirm it from the inbox before it will deliver anything.

Protocol Email
Endpoint your notification address
SNS email subscription creation screen
order-notification · email subscription
05
Create the shared IAM role

One execution role, trusted by Lambda, used by both functions in the pipeline.

Trusted entity Lambda
  • AWSLambdaBasicExecutionRole
  • AmazonSQSFullAccess
  • AmazonSNSFullAccess
IAM role creation screen with AWSLambdaBasicExecutionRole, AmazonSQSFullAccess, AmazonSNSFullAccess attached
shared execution role · attached policies
06
Create the CreateOrder function

Accepts the API request and hands it straight to the queue — it does no fulfillment work itself.

Name CreateOrder
Runtime Python 3.12
Env var QUEUE_URL
  • Receive the API request
  • Send the order as a message to SQS
CreateOrder Lambda function configuration screen
CreateOrder · function config
CreateOrder Lambda environment variable QUEUE_URL configuration
CreateOrder · QUEUE_URL env var
07
Wire up API Gateway

A REST API in front of CreateOrder, deployed to a live stage.

Resource /orders
Method POST
Integration CreateOrder Lambda
Stage Prod
API Gateway resource /orders with POST method integrated to CreateOrder Lambda
/orders · POST → CreateOrder
08
Create the ProcessOrder function

Triggered directly by the queue — this is where the actual order handling and notification happen.

Name ProcessOrder
Trigger SQS · order-queue
Batch size 1
Env var SNS_TOPIC_ARN
  • Read the message off SQS
  • Process the order
  • Publish a notification to SNS
ProcessOrder Lambda SQS trigger configuration, order-queue, batch size 1
ProcessOrder · SQS trigger
ProcessOrder Lambda environment variable SNS_TOPIC_ARN configuration
ProcessOrder · SNS_TOPIC_ARN env var
09
Test end to end

Submit an order through the test front end and confirm it comes back around as an email.

  • Place an order → API returns a success response immediately
  • Message lands on order-queue → ProcessOrder picks it up
  • SNS fires → confirmation email arrives in the subscribed inbox
Test order form web page with Place Order button
test page · place order
Order submitted successfully confirmation message on the test page
order submitted successfully
Confirmation email received in inbox with order details
confirmation email received
Lambda source

The two functions, in full

CreateOrder only ever writes to the queue. ProcessOrder only ever reads from it and reports the outcome — neither one knows the other exists.

CreateOrder — receives the request, enqueues the order

create_order.py
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
        })
    }

ProcessOrder — consumes the queue, notifies the customer

process_order.py
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"]
        })
    }
Note: the original snippet returns 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.
Verification

What a successful run looks like

Request

Place order

Submitting the test form returns a 200 immediately — the customer never waits on fulfillment.

Response

"Order Created"

The API responds with the generated order ID before ProcessOrder has even run.

Confirmation

Email arrives

Moments later, the subscribed inbox receives the order confirmation published through SNS.