I am trying to set up cloud watch alarm using SNS metrics by CFN scripts. I am not able to add the PhoneNumberDirect in the cfn code but on the console this metrics is there in the console while selecting manually.
SNSAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: "OTP-Alarm"
AlarmDescription: "Alarm for OTP failures"
Namespace: "AWS/SNS"
PhoneNumber: "PhoneNumberDirect"
MetricName: "NumberOfNotificationsFailed"
#Dimensions:
#- Name: "PhoneNumber"
# Value: "PhoneNumberDirect"
Statistic: "Average"
ComparisonOperator: "GreaterThanThreshold"
Threshold: 20
EvaluationPeriods: 1
It looks like you tried using Dimensions
as well but was not successful.
I was able to create a similar alarm on the same metric with the following CloudFormation template:
AWSTemplateFormatVersion: 2010-09-09
Resources:
MyAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
ActionsEnabled: true
AlarmActions:
- 'arn:aws:sns:us-east-1:...:Default_CloudWatch_Alarms_Topic'
AlarmDescription: Description
AlarmName: Test Alarm
ComparisonOperator: GreaterThanOrEqualToThreshold
DatapointsToAlarm: 1
Dimensions:
- Name: PhoneNumber
Value: PhoneNumberDirect
MetricName: NumberOfNotificationsFailed
Namespace: AWS/SNS
Period: 300
Statistic: Sum
Threshold: 1
TreatMissingData: missing
EvaluationPeriods: 1
Feel free to play around with this to get your desired output.