我创建了一个闹钟,之后想删除它... boto 2的documentation没有显示如何执行此操作。
有任何帮助吗? 感谢
答案 0 :(得分:2)
如果要删除警报,则所需的API为KafkaTableSource source = Kafka08JsonTableSource.builder()// set Kafka topic
.forTopic("alerting")
// set Kafka consumer properties
.withKafkaProperties(getKafkaProperties())
// set Table schema
.withSchema(TableSchema.builder()
.field("tenant", Types.STRING())
.field("message", Types.STRING())
.field("frequency", Types.LONG())
.field("timestamp", Types.SQL_TIMESTAMP()).build())
.failOnMissingField(true)
.withRowtimeAttribute(
// "timestamp" is rowtime attribute
"timestamp",
// value of "timestamp" is extracted from existing field with same name
new ExistingField("timestamp"),
// values of "timestamp" are at most out-of-order by 30 seconds
new BoundedOutOfOrderTimestamps(TimeUnit.DAYS.toMillis(1)))
.build();
//register the alerting topic as kafka
tEnv.registerTableSource("kafka", source);
Table results = tEnv.sqlQuery("SELECT tenant, message, SUM(frequency) " +
"FROM kafka " +
"GROUP BY HOP(rowtime, INTERVAL '1' SECOND, INTERVAL '5' SECOND), tenant, message");
tEnv.toAppendStream(results, Row.class).print();
。您在问题中的链接提到了它(搜索DeleteAlarms
)。
另外,boto 3是推荐使用的版本,以下是您需要的API:https://boto3.readthedocs.io/en/latest/reference/services/cloudwatch.html#CloudWatch.Client.delete_alarms
如何使用Boto 3:
进行操作的示例delete_alarms
Boto 2示例:
import boto3
client = boto3.client('cloudwatch')
client.delete_alarms(AlarmNames=['SomeAlarmName'])
如果你不知道这个名字,你可以得到一个警报列表(对于boto 2和3都是一样的):
import boto
client = boto.connect_cloudwatch()
client.delete_alarms('SomeAlarmName')
答案 1 :(得分:1)
你应该使用Boto3。但如果你与Boto2联系在一起,那么:
import boto
cw = boto.connect_cloudwatch()
alarms= cw.describe_alarms()
for alarm in alarms:
print alarm.name
检查是否列出了要删除的警报。然后使用该名称:
cw.delete_alarms([<alarm_to_be_deleted>])