Reputation: 3460
According to the documentation, I can use Python to disable alarms like this. However, this option only gives the AlarmNames parameter. I want to disable alarms using ARNs.
client = boto3.client('cloudwatch')
disable_alarm = client.disable_alarm_actions(AlarmNames=[name])
One option could be to use the ARN to first get the name and then disable it using the name. But how can I do so?
Upvotes: 0
Views: 104
Reputation: 954
If there really is no other option, you may need to query all alarms with client.describe_alarms()
or an equivalent paginator, and iterate over them until you find one with a matching ARN.
The following example lists all AlarmArn => AlarmName associations in us-east-1
:
session = boto3.session.Session(region_name="us-east-1")
client = session.client("cloudwatch")
nextToken = {}
while True:
result = client.describe_alarms(MaxRecords=100, **nextToken)
if 'MetricAlarms' in result:
for alarm in result['MetricAlarms']:
print("{} => {}".format(alarm['AlarmArn'], alarm['AlarmName']))
if 'CompositeAlarms' in result:
for alarm in result['CompositeAlarms']:
print("{} => {}".format(alarm['AlarmArn'], alarm['AlarmName']))
if 'NextToken' in result:
nextToken = {'NextToken': result['NextToken']}
else:
break
Upvotes: 1