Amazon Web Services (AWS) - Enable or disable Cloudwatch Alarm Actions using the AWS CLI

by
Jeremy Canfield |
Updated: February 09 2024
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
Cloudwatch alarms can be used to alert you when some conditiion is met, such as:
- an EC2 instance has high CPU or high memory usage
- an EC2 instance in a Load Balancer Target Group health check returns "unhealthy"
- a Lambda Function has one or more errors
The aws cloudwatch describe-alarms command can be used to list the cloudwatch alarms you have created.
aws cloudwatch describe-alarms
Something like this should be returned. Notice in this example that ActionsEnabled is true meaning the Alarm Actions are enabled.
{
"MetricAlarms": [
{
"AlarmName": "high-cpu",
"AlarmArn": "arn:aws:cloudwatch:us-east-1:123456789012:alarm:high-cpu",
"AlarmDescription": "CPU Utilization exceeds 10% in the last 5 minutes",
"AlarmConfigurationUpdatedTimestamp": "2023-06-21T01:53:16.629000+00:00",
"ActionsEnabled": true,
"OKActions": [],
"AlarmActions": [
"arn:aws:sns:us-east-1:123456789012:my-topic"
],
"InsufficientDataActions": [
"arn:aws:sns:us-east-1:123456789012:my-topic"
],
"StateValue": "OK",
"StateReason": "Threshold Crossed: 1 datapoints [1.3967213114600159 (21/06/23 01:44:00)] was not greater than the threshold (10.0).",
"StateReasonData": "{\"version\":\"1.0\",\"queryDate\":\"2024-01-16T06:23:48.140+0000\",\"startDate\":\"2024-01-16T06:20:00.000+0000\",\"unit\":\"Percent\",\"statistic\":\"Average\",\"period\":60,\"recentDatapoints\":[0.0015606770489069999],\"threshold\":10.0,\"evaluatedDatapoints\":[{\"timestamp\":\"2024-01-16T06:20:00.000+0000\",\"sampleCount\":1.0,\"value\":0.0015606770489069999}]}",
"StateUpdatedTimestamp": "2023-06-21T01:54:00.144000+00:00",
"MetricName": "CPUUtilization",
"Namespace": "AWS/EC2",
"Statistic": "Average",
"Dimensions": [
{
"Name": "InstanceId",
"Value": "i-0d241234f9665abcd"
}
],
"Period": 300,
"Unit": "Percent",
"EvaluationPeriods": 1,
"Threshold": 10.0,
"ComparisonOperator": "GreaterThanThreshold"
}
],
"CompositeAlarms": []
}
The aws cloudwatch disable-alarm-actions command can be used to disable the Alarm Actions.
aws cloudwatch disable-alarm-actions --alarm-names high-cpu
The aws cloudwatch enable-alarm-actions command can be used to enable the Alarm Actions.
aws cloudwatch enable-alarm-actions --alarm-names high-cpu
Did you find this article helpful?
If so, consider buying me a coffee over at