Full SNS Setup on AWS — Short & Clear
Step 1 — Create SNS Topic
- AWS Console → SNS → Topics
- Click Create topic
- Type: Standard
- Name:
order-processer-notification-nishan - Click Create topic
- Copy the Topic ARN shown on the next page
Step 2 — Create Subscription (Use SMS to avoid Gmail issues)
- Click your topic name
- Click Create subscription
- Fill in:
| Field | Value |
|---|---|
| Protocol | SMS |
| Endpoint | +9779XXXXXXXX (your Nepal number) |
- Click Create subscription
- ✅ No email confirmation needed — active immediately
Step 3 — Give Lambda Permission
- IAM → Roles
- Find your processor Lambda role
- Add permissions → Attach policies
- Search and attach AmazonSNSFullAccess
- Click Add permissions
Step 4 — Add SNS Code to Processor Lambda
- Lambda → processor function
- Paste this code and click Deploy
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 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 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;
}
};
Step 5 — Test It
- Upload a file to your source S3 bucket
- Watch the flow trigger automatically
- Check CloudWatch logs for ✅ messages
- You should receive an SMS on your phone ✅
Full Flow Summary
S3 (upload) → receiver Lambda → SQS → processor Lambda
├── DynamoDB ✅
├── S3 output ✅
└── SNS (SMS) ✅
That's it! 🚀