Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create CloudWatch alarm on all instances in an RDS cluster

I have an RDS Aurora cluster with 2 instances, a reader and a writer.

I created a CloudWatch alarm on DatabaseConnections with dimension DBClusterIdentifier.

But the alarm only works on one instance (the writer). The alarm will not trigger if the reader exceeds the threshold.

How do I get an alarm to trigger if any RDS instance crosses the threshold.

This is my code:

resource "aws_cloudwatch_metric_alarm" "rds-connection-count-alarm" {
  alarm_name = "rds-connection-count-alarm"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods = "1"
  metric_name = "DatabaseConnections"
  namespace = "AWS/RDS"
  period = "60"
  statistic = "Maximum"
  threshold = "1000" # max 2000 for db.r4.xlarge rds instances

  dimensions {
    DBClusterIdentifier = "${aws_rds_cluster.my_rds_cluster.id}"
  }

  alarm_description = "Alerts Slack if the DB connection count exceeds 1000"
  alarm_actions = ["${data.aws_sns_topic.notification_topic.arn}"]
  ok_actions = ["${data.aws_sns_topic.notification_topic.arn}"]
  insufficient_data_actions = []

  lifecycle {
    create_before_destroy = true
  }
}
like image 462
Jay Avatar asked Sep 13 '25 00:09

Jay


1 Answers

I recommend using roles to monitor connections on both your writer and reader when using RDS Aurora. There are two advantages to this:

  1. You can individually track and set alarms for the writer and reader
  2. You don't have to update your monitor or alarms if your instance is replaced because each instance will have one role or another.

Note that if you have multiple readers the reader role is averaging them.

Cloudwatch metrics using RDS roles in AWS

like image 78
Seamus Avatar answered Sep 14 '25 13:09

Seamus