Messaging with Amazon Simple
Notification Service (SNS)
Task 2: Monitor SNS Performance with CloudWatch
Objective: Track Amazon SNS metrics, set alarms, and analyze logs to
ensure reliable message delivery and identify bottlenecks.
Key Steps
1. Access Key SNS Metrics:
o Critical Metrics:
NumberOfMessagesPublished (total messages sent to the
topic).
NumberOfNotificationsDelivered (successful deliveries).
NumberOfNotificationsFailed (failed deliveries).
SMSSuccessRate (SMS delivery success percentage).
DeliveryAttempts (retries for HTTP/S endpoints).
2. Set Up Alarms:
o Example Alarm for Failed Deliveries:
bash
Copy
aws cloudwatch put-metric-alarm \
--alarm-name "SNS-Failed-Deliveries" \
--metric-name NumberOfNotificationsFailed \
--namespace AWS/SNS \
--statistic Sum \
--threshold 1 \
, --comparison-operator GreaterThanOrEqualToThreshold \
--evaluation-periods 1 \
--alarm-actions "arn:aws:sns:us-east-1:123456789012:AlertTopic"
3. Create Dashboards:
o Visualize metrics
like NumberOfMessagesPublished vs. NumberOfNotificationsDeliv
ered.
o Add widgets for SMS costs (SMSMonthToDateSpentUSD) and
success rates.
4. Enable Delivery Status Logging:
o Log delivery attempts to CloudWatch Logs for HTTP/S, Lambda,
or other endpoints.
5. Use Anomaly Detection:
o Detect unusual spikes/drops in message activity using ML-based
anomaly detection.
Possible Questions & Answers
Q1: How do I monitor SMS-specific issues?
A1:
Track SMSSuccessRate and SMSMonthToDateSpentUSD metrics.
Set alarms for low success rates:
bash
Copy
aws cloudwatch put-metric-alarm \
--alarm-name "Low-SMS-Success" \
--metric-name SMSSuccessRate \
--threshold 90 \
--comparison-operator LessThanThreshold
Check carrier restrictions or blacklisted numbers if failures occur.