Skip to content

Instantly share code, notes, and snippets.

@tfentonz
Created August 1, 2022 01:36
Show Gist options
  • Save tfentonz/1586315995cd78bfc2f237be9b45528e to your computer and use it in GitHub Desktop.
Save tfentonz/1586315995cd78bfc2f237be9b45528e to your computer and use it in GitHub Desktop.
CloudWatch alarms for multiple accounts and regions
#!/bin/bash
profile_prefix="ProfilePrefix"
region="us-east-1"
for i in Account1 Account2 Account3
do
length=$(aws cloudwatch describe-alarms \
--state-value ALARM \
--query "length(MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`])" \
--profile "${profile_prefix}-${i}" \
--region "$region")
if [ "$length" != "0" ]; then
echo "# $i"
aws cloudwatch describe-alarms \
--state-value ALARM \
--query "MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`].[AlarmName,AlarmDescription]" \
--output text \
--profile "${profile_prefix}-${i}" \
--region "$region"
fi
done
region="us-east-2"
for i in Account4 Account5
do
length=$(aws cloudwatch describe-alarms \
--state-value ALARM \
--query "length(MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`])" \
--profile "${profile_prefix}-${i}" \
--region "$region")
if [ "$length" != "0" ]; then
echo "# $i"
aws cloudwatch describe-alarms \
--state-value ALARM \
--query "MetricAlarms[?starts_with(AlarmActions[0], \`arn:aws:autoscaling\`) == \`false\`].[AlarmName,AlarmDescription]" \
--output text \
--profile "${profile_prefix}-${i}" \
--region "$region"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment