【发布时间】:2015-05-13 23:13:22
【问题描述】:
我想用 cloudwatch 监控一个名为“topic”的主题。
使用 cloudwatch,我希望当这个主题“主题”的 NumberOfMessagesPublished > 100 时,我想向其他名为“cloudwatchSNS”的主题发送通知。
我尝试使用以下代码执行此操作,但出现此错误:
AttributeError: 'ResultSet' object has no attribute 'create_alarm'
你能帮我把它正常工作吗?
import boto.sns
from boto.ec2.cloudwatch import MetricAlarm
import boto.ec2.cloudwatch
sns = boto.sns.connect_to_region("us-east-1")
cloudwatch = boto.ec2.cloudwatch.connect_to_region("us-east-1")
#topic to send notification when NumberOfMessagesPublished > 100
topicToSendNotification = sns.create_topic("cloudwatchSNS")
topicArnToSendNotification = topicarn['CreateTopicResponse']['CreateTopicResult']['TopicArn']
#topicName to control the number of messages published
topicNameToMonitor = "topic"
#subscriptor in topic to receive an email when NumberOfMessagesPublished > 100
subscription = sns.subscribe(topicArnToSendNotification, "email", "mail@mail.com")
metric = cloudwatch.list_metrics(dimensions={'TopicName':topicNameToMonitor},
metric_name="NumberOfMessagesPublished")
alarmName = "test"
metric.create_alarm(name=alarmName, comparison='>=', threshold=100, period=300,
evaluation_periods=2, statistic='Average', alarm_actions=[topicarnToSendNotification])
【问题讨论】:
-
您应该发布错误的完整回溯并标记错误的代码行(使用易于识别的注释等)。到目前为止发布的消息只是表明该对象没有所需的属性(听听)。
标签: python amazon-web-services boto amazon-sns