简体   繁体   中英

get the Alarm object of CloudWatch using boto 2

I created an alarm and want to delete it afterward... The documentation for boto 2 doesn't show how to do that.

Any help ? Thanks

If you want to delete alarms, the API you need is DeleteAlarms . The link you have in your question is mentioning it (search for delete_alarms ).

Also, boto 3 is the recommended version to use and here is the API you need: https://boto3.readthedocs.io/en/latest/reference/services/cloudwatch.html#CloudWatch.Client.delete_alarms

Example of how to do it with Boto 3:

import boto3
client = boto3.client('cloudwatch')
client.delete_alarms(AlarmNames=['SomeAlarmName'])

Boto 2 example:

import boto
client = boto.connect_cloudwatch()
client.delete_alarms('SomeAlarmName')

If you don't know the name, you can get a list of alarms with (the same for boto 2 and 3):

client.describe_alarms()

You should use Boto3. But if you are tied to Boto2, then:

import boto
cw = boto.connect_cloudwatch()
alarms= cw.describe_alarms()
for alarm in alarms:
  print alarm.name

Check if the alarm you want to delete is listed. Then use that name:

cw.delete_alarms([<alarm_to_be_deleted>])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM