Frequently Asked Questions
Implement a system using CloudWatch Logs and Lambda. SNS logs delivery attempts to CloudWatch, which triggers a Lambda function. This function parses the logs, queries a DynamoDB table using a Global Secondary Index (GSI) to find the message's internal ID, and updates its status.
The GSI allows efficient lookup of the internal message ID using the SNS message ID. Since SNS logs don't contain our internal ID, the GSI bridges this gap by indexing snsMessageId and projecting internalMessageId, enabling quick retrieval of the corresponding record in DynamoDB.
AWS SNS doesn't natively offer HTTP callbacks for SMS delivery status. This guide's architecture provides a workaround using CloudWatch Logs and Lambda to indirectly capture and process status updates.
Always prefer IAM roles for production deployments. For local development, you can use access keys stored in .env.local. However, in production environments like Vercel, EC2, or ECS, IAM roles provide a more secure and manageable way to grant permissions to your application without exposing credentials.
Create a Next.js API route that uses the AWS SDK for JavaScript v3 to publish messages to an SNS topic. This API route should handle input validation, generate a unique internal message ID, store the initial message status in DynamoDB, and publish the SMS message via SNS.
The system uses Next.js for the frontend and API routes, AWS SNS for sending SMS, AWS CloudWatch Logs for capturing delivery status, AWS Lambda for processing logs, AWS DynamoDB for storing message status, AWS IAM for permissions, and the AWS SDK for JavaScript v3 for interacting with AWS services.
Yes, you can customize the sender ID by using MessageAttributes in the PublishCommandInput when sending the SMS message. Set 'AWS.SNS.SMS.SenderID' to your desired alphanumeric sender ID (up to 11 characters).
Lambda acts as the processing engine triggered by CloudWatch Logs. It parses SNS delivery status logs, queries the DynamoDB GSI using the SNS message ID, retrieves the internal message ID, and updates the message status in DynamoDB.
Create a DynamoDB table with internalMessageId as the primary key. Add a Global Secondary Index (GSI) with snsMessageId as the partition key and project the internalMessageId attribute. This allows efficient lookup of the internal ID based on the SNS message ID logged by CloudWatch.
Use the command npx create-next-app@latest sns-status-tracker --typescript in your terminal. This creates a new Next.js project with TypeScript. Then, navigate into the project directory using cd sns-status-tracker.
Run npm install @aws-sdk/client-sns @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb to install the necessary AWS SDK clients for interacting with SNS and DynamoDB.
For local development, create a .env.local file in your project root. Store AWS credentials there. For production, use IAM roles or platform-specific secret management systems, keeping credentials out of your codebase.
You'll need Node.js and npm/yarn, an AWS account, AWS CLI configured, and a basic understanding of Next.js, React, and AWS concepts. Also, ensure you have appropriate AWS permissions to create the required resources.
SNS logs a JSON object containing details like message ID (messageId), delivery status (status), provider response (providerResponse), and timestamp. The Lambda function parses this data to update the message status in DynamoDB.