Complete AWS Serverless Order Processing — Full Guide
What We Are Building
S3 (upload JSON) → receiver Lambda → SQS → processor Lambda
↓ ├── DynamoDB
CloudWatch ├── S3 output
└── SNS (SMS)
Service Full Forms
| Short | Full Form | What it does |
|---|---|---|
| S3 | Simple Storage Service | Stores files/JSON on cloud |
| Lambda | Lambda | Runs code without a server |
| SQS | Simple Queue Service | Holds messages in a queue |
| DynamoDB | Amazon DynamoDB | NoSQL database |
| SNS | Simple Notification Service | Sends SMS/email alerts |
| IAM | Identity and Access Management | Controls permissions |
| CloudWatch | Amazon CloudWatch | Monitors logs |
STEP 1 — Create IAM Role
IAM Role gives your Lambda permission to use S3, SQS, DynamoDB, SNS, CloudWatch
- AWS Console → IAM → Roles
- Click Create role
- Trusted entity: AWS Service
- Use case: Lambda
- Click Next
- Search and attach these policies:
| Policy Name | Why |
|---|---|
AmazonS3FullAccess | Read/write S3 |
AmazonSQSFullAccess | Read/write SQS |
AmazonDynamoDBFullAccess | Read/write DynamoDB |
AmazonSNSFullAccess | Send notifications |
CloudWatchFullAccess | Write logs |
- Role name:
lambda-order-role-nishan - Click Create role ✅
STEP 2 — Create Two S3 Buckets
S3 = Simple Storage Service — stores your JSON files
Bucket 1 (Input — where you upload JSON)
- AWS Console → S3 → Create bucket
- Bucket name:
order-input-nishan - Region:
us-east-1 - Everything else default
- Click Create bucket ✅
Bucket 2 (Output — where processed files go)
- Click Create bucket again
- Bucket name:
order-process-nishan - Region:
us-east-1 - Click Create bucket ✅
STEP 3 — Create SQS Queue
SQS = Simple Queue Service — holds orders between two Lambdas
- AWS Console → SQS → Create queue
- Type: Standard
- Name:
order-queue-nishan - Scroll down → Dead-letter queue → Enable it
- Set Maximum receives:
3 - Click Create queue
- Copy the Queue URL — you'll need it ✅
STEP 4 — Create DynamoDB Table
DynamoDB — stores processed order data as records
- AWS Console → DynamoDB → Tables → Create table
- Fill in:
| Field | Value |
|---|---|
| Table name | ordernishan |
| Partition key | orderId (String) |
- Everything else default
- Click Create table ✅
STEP 5 — Create SNS Topic
SNS = Simple Notification Service — sends you SMS when order is processed
- AWS Console → SNS → Topics
- Click Create topic
- Type: Standard
- Name:
order-processer-notification-nishan - Click Create topic
- Copy the Topic ARN ✅
Add SMS Subscription
- Click your topic name
- Click Create subscription
| Field | Value |
|---|---|
| Protocol | SMS |
| Endpoint | +9779XXXXXXXX |
- Click Create subscription ✅ (works immediately, no confirmation needed)
STEP 6 — Create Receiver Lambda
This Lambda watches S3, picks up uploaded JSON and sends to SQS
Create the Function
- AWS Console → Lambda → Create function
- Fill in:
| Field | Value |
|---|---|
| Function name | receiver |
| Runtime | Node.js 18.x |
| Execution role | lambda-order-role-nishan |
- Click Create function
Add S3 Trigger
- Click Add trigger
- Select S3
- Bucket:
order-input-nishan - Event type: PUT
- Click Add ✅
Paste Receiver Code
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
const sqsClient = new SQSClient({});
const s3Client = new S3Client({});
// Your SQS Queue URL
const QUEUE_URL = "https://sqs.us-east-1.amazonaws.com/237795118651/order-queue-nishan";
export const handler = async (event) => {
try {
// Get the uploaded file info from S3 event
const bucket = event.Records[0].s3.bucket.name;
const key = decodeURIComponent(event.Records[0].s3.object.key);
console.log(`📥 File uploaded: ${key} from bucket: ${bucket}`);
// Read the JSON file from S3
const s3Response = await s3Client.send(new GetObjectCommand({
Bucket: bucket,
Key: key
}));
// Convert stream to string
const bodyContents = await s3Response.Body.transformToString();
const orderData = JSON.parse(bodyContents);
console.log("📦 Order data received:", orderData);
// Send order to SQS queue
await sqsClient.send(new SendMessageCommand({
QueueUrl: QUEUE_URL,
MessageBody: JSON.stringify(orderData)
}));
console.log("✅ Order sent to SQS successfully");
return { statusCode: 200 };
} catch (error) {
console.error("❌ Receiver error:", error);
throw error;
}
};
Click Deploy ✅
STEP 7 — Create Processor Lambda
This Lambda reads from SQS, saves to DynamoDB, S3, and sends SNS
Create the Function
- AWS Console → Lambda → Create function
- Fill in:
| Field | Value |
|---|---|
| Function name | processor |
| Runtime | Node.js 18.x |
| Execution role | lambda-order-role-nishan |
- Click Create function
Add SQS Trigger
- Click Add trigger
- Select SQS
- Queue:
order-queue-nishan - Batch size:
1 - Click Add ✅
Paste Processor Code
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { SNSClient, PublishCommand } from "@aws-sdk/client-sns";
const dynamoClient = new DynamoDBClient({});
const s3Client = new S3Client({});
const snsClient = new SNSClient({});
const SNS_TOPIC_ARN = "arn:aws:sns:us-east-1:237795118651:order-processer-notification-nishan";
const OUTPUT_BUCKET = "order-process-nishan";
export const handler = async (event) => {
try {
for (const record of event.Records) {
const messageBody = JSON.parse(record.body);
const orderId = messageBody.orderId;
if (!orderId) {
console.error("Missing orderId");
continue;
}
// STEP 1: Save to DynamoDB
await dynamoClient.send(new PutItemCommand({
TableName: "ordernishan",
Item: {
orderId: { S: orderId },
customer: { S: messageBody.customer || "UNKNOWN" },
amount: { N: String(messageBody.amount || 0) },
status: { S: "PROCESSED" },
createdAt: { S: new Date().toISOString() }
}
}));
console.log(`✅ Saved to DynamoDB: ${orderId}`);
// STEP 2: Save processed JSON to S3
await s3Client.send(new PutObjectCommand({
Bucket: OUTPUT_BUCKET,
Key: `processed/${orderId}.json`,
Body: JSON.stringify({ orderId, ...messageBody, status: "PROCESSED" }),
ContentType: "application/json"
}));
console.log(`✅ Saved to S3: ${orderId}`);
// STEP 3: Send SNS SMS Notification
await snsClient.send(new PublishCommand({
TopicArn: SNS_TOPIC_ARN,
Message: `Order ${orderId} processed! Customer: ${messageBody.customer}, Amount: $${messageBody.amount}`
}));
console.log(`✅ SNS sent for: ${orderId}`);
}
return { statusCode: 200 };
} catch (error) {
console.error("❌ Error:", error);
throw error;
}
};
Click Deploy ✅
STEP 8 — Set Lambda Timeout
Lambda runs max 15 min (900 sec). Set it to 2 min to be safe.
For both receiver and processor Lambda:
- Lambda → your function → Configuration
- Click General configuration → Edit
- Timeout:
2 min 0 sec - Click Save ✅
STEP 9 — Test Everything
Create a test JSON file on your computer:
{
"orderId": "ORD-001",
"customer": "Nishan",
"amount": 250
}
Upload it:
- Go to S3 →
order-input-nishan - Click Upload → upload your JSON file
Check results:
| Where | What to check |
|---|---|
CloudWatch → Log groups → /aws/lambda/receiver | See if file was received |
CloudWatch → Log groups → /aws/lambda/processor | See if order was processed |
DynamoDB → ordernishan → Explore items | See your order saved |
S3 → order-process-nishan → processed/ folder | See processed JSON |
| Your phone | Receive SMS notification ✅ |
Final Flow Summary
1. You upload JSON → order-input-nishan (S3)
2. S3 triggers → receiver Lambda
3. receiver Lambda → sends to SQS queue
4. SQS triggers → processor Lambda
5. processor Lambda:
├── Saves to DynamoDB ✅
├── Saves to order-process-nishan (S3) ✅
└── Sends SMS via SNS ✅
6. CloudWatch logs everything 📋
🎉 Your full serverless AWS pipeline is complete! Every time you upload a JSON order to S3, the whole system runs automatically without any server.