Lab - Design and Manage Pub/Sub
Messaging with Amazon Simple
Notification Service (SNS)
Task 4: Analyze SNS Performance Using Amazon CloudWatch
Step 1: Access SNS Metrics in CloudWatch
Amazon SNS automatically publishes metrics to CloudWatch. Key metrics
include:
Metric Purpose
NumberOfMessagesPublis
Total messages published to the topic.
hed
NumberOfNotificationsDeli
Messages successfully delivered to subscribers.
vered
NumberOfNotificationsFail Messages that failed delivery (e.g., invalid
ed endpoints, throttling).
Percentage of SMS messages delivered
SMSSuccessRate
successfully.
SMSMonthToDateSpentUS
Total SMS costs incurred in the current month.
D
Number of attempts to deliver messages (useful
DeliveryAttempts
for HTTP/S retries).
How to View Metrics:
1. AWS Console:
o Go to CloudWatch > Metrics > All metrics > SNS.
o Filter by Topic Metrics or Platform Application Metrics (for
SMS).
2. AWS CLI:
bash
Copy
, aws cloudwatch get-metric-statistics \
--namespace AWS/SNS \
--metric-name NumberOfNotificationsDelivered \
--dimensions Name=TopicName,Value=MyTopic \
--start-time 2023-10-01T00:00:00Z \
--end-time 2023-10-01T23:59:59Z \
--period 3600 \
--statistics Sum
Step 2: Set Up CloudWatch Alarms
Create alarms to detect anomalies or failures:
Example 1: Alarm for Failed Deliveries
bash
Copy
aws cloudwatch put-metric-alarm \
--alarm-name "SNS-Delivery-Failures" \
--metric-name NumberOfNotificationsFailed \
--namespace AWS/SNS \
--statistic Sum \
--period 300 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold \
--evaluation-periods 1 \
--alarm-actions "arn:aws:sns:us-east-1:123456789012:AlertTopic"
Example 2: SMS Cost Alarm
Trigger if SMS costs exceed $500 in a month:
bash
Copy
Messaging with Amazon Simple
Notification Service (SNS)
Task 4: Analyze SNS Performance Using Amazon CloudWatch
Step 1: Access SNS Metrics in CloudWatch
Amazon SNS automatically publishes metrics to CloudWatch. Key metrics
include:
Metric Purpose
NumberOfMessagesPublis
Total messages published to the topic.
hed
NumberOfNotificationsDeli
Messages successfully delivered to subscribers.
vered
NumberOfNotificationsFail Messages that failed delivery (e.g., invalid
ed endpoints, throttling).
Percentage of SMS messages delivered
SMSSuccessRate
successfully.
SMSMonthToDateSpentUS
Total SMS costs incurred in the current month.
D
Number of attempts to deliver messages (useful
DeliveryAttempts
for HTTP/S retries).
How to View Metrics:
1. AWS Console:
o Go to CloudWatch > Metrics > All metrics > SNS.
o Filter by Topic Metrics or Platform Application Metrics (for
SMS).
2. AWS CLI:
bash
Copy
, aws cloudwatch get-metric-statistics \
--namespace AWS/SNS \
--metric-name NumberOfNotificationsDelivered \
--dimensions Name=TopicName,Value=MyTopic \
--start-time 2023-10-01T00:00:00Z \
--end-time 2023-10-01T23:59:59Z \
--period 3600 \
--statistics Sum
Step 2: Set Up CloudWatch Alarms
Create alarms to detect anomalies or failures:
Example 1: Alarm for Failed Deliveries
bash
Copy
aws cloudwatch put-metric-alarm \
--alarm-name "SNS-Delivery-Failures" \
--metric-name NumberOfNotificationsFailed \
--namespace AWS/SNS \
--statistic Sum \
--period 300 \
--threshold 1 \
--comparison-operator GreaterThanOrEqualToThreshold \
--evaluation-periods 1 \
--alarm-actions "arn:aws:sns:us-east-1:123456789012:AlertTopic"
Example 2: SMS Cost Alarm
Trigger if SMS costs exceed $500 in a month:
bash
Copy