Frequently Asked Questions
Configure AWS SNS to send delivery status notifications to a dedicated RedwoodJS endpoint. Create an IAM policy and role for SNS, then create an SNS Topic. In RedwoodJS, install necessary dependencies, configure environment variables with AWS credentials and Topic ARN, implement your database schema and SMS service to send messages, and implement your callback handler in a RedwoodJS function. Finally, connect SNS to the callback endpoint by creating a subscription and confirming it. This completes the setup for real-time delivery status updates in your application.
Delivery status callbacks provide real-time updates on the delivery status of your SMS messages. This is crucial for tracking message success rates, triggering follow-up actions, and providing better feedback to users. Unlike standard SNS publish calls, which only confirm that AWS accepted the request, callbacks provide insights into whether the message reached the end user's device.
The standard `publish` call in AWS SNS only confirms that the message request was successfully received and queued by the SNS service. It doesn't track the actual delivery to the user's device. This is why delivery status callbacks are essential for confirming message delivery outcomes and identifying any delivery failures.
Use 'Transactional' for SMS messages related to application functionality, such as one-time passwords (OTPs), purchase confirmations, and delivery notifications. Use 'Promotional' for marketing-related messages, special offers, or other non-critical communications. The distinction helps manage costs and ensures compliance with regulations.
Yes, you can receive delivery status updates directly via HTTPS endpoints without using CloudWatch Logs. While CloudWatch Logs offer a monitoring option, this guide focuses on setting up direct HTTPS callbacks to a RedwoodJS function for real-time status updates. Configuring basic logging permissions might still be a prerequisite during AWS console setup, however.
In the AWS IAM service, go to Policies, click 'Create Policy', and define a policy allowing SNS to manage CloudWatch Logs. This policy is often required when initially configuring SMS preferences. Remember to apply the principle of least privilege by limiting resources and actions, if CloudWatch is the core of your monitoring, as excessive permissions can present security risks.
Implement robust security measures like signature validation, using HTTPS, and protecting AWS credentials. Use the `aws-sns-message-validator` package to verify signatures of all incoming messages. Always use an HTTPS endpoint for your callbacks, and store sensitive information like AWS keys securely via environment variables that are never committed to version control. Also follow the principle of least privilege by creating restrictive IAM roles.
Mock the AWS SDK using Jest. This isolates your service logic and enables testing different scenarios like successful and failed publishing without actually sending messages or interacting with AWS. You can check that the PublishCommand is called with the correct parameters and that database records are appropriately updated based on the success or failure of the mocked SNS responses.
Upon creating an SNS subscription, AWS sends a `SubscriptionConfirmation` message to your callback URL with a unique `SubscribeURL`. For manual confirmation, copy this `SubscribeURL` from your RedwoodJS logs and paste it into a browser. For automatic confirmation, implement a `fetch` call to the `SubscribeURL` in your callback handler function.
The `awsMessageId` is a unique identifier returned by AWS SNS when you initially publish an SMS message. It is crucial for linking the delivery status callback to the specific message sent. The callback notification includes this ID, enabling you to update the status of the corresponding message in your database.
If signature validation fails, reject the request immediately with a 403 Forbidden response. This protects your application from potentially malicious or spoofed notifications. Ensure you're using `aws-sns-message-validator` or a similar library correctly, and verify that the incoming message is indeed being sent by AWS SNS.
Content Loading Error
We encountered an error while processing this content.