Skip to content

Instantly share code, notes, and snippets.

@billyxs
Last active August 22, 2023 14:56
Show Gist options
  • Save billyxs/1d170ec022dcd4039827977fe0078b8a to your computer and use it in GitHub Desktop.
Save billyxs/1d170ec022dcd4039827977fe0078b8a to your computer and use it in GitHub Desktop.
Delete a list of cloudwatch alarms with names that contain a string
#!/bin/bash
ALARM_NAME_CONTAINS_STRING='alarm-name'
ALARMS=$(aws cloudwatch describe-alarms \
| jq '.MetricAlarms[].AlarmName' \
| sed "s/\"//g" \
| awk "/$ALARM_NAME_CONTAINS_STRING/")
for alarm in $ALARMS;
do
echo "Deleting alarm: $alarm"
aws cloudwatch delete-alarms --alarm-names $alarm
done
@edlins
Copy link

edlins commented Aug 22, 2023

9a10
> IFS=$(echo -en "\n\b")

deletes alarms with spaces in the name as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment