Configures autoscaling for Aurora read replicas based on CPU utilization.

Terraform Template

resource "aws_appautoscaling_policy" "replicas" {
  name = "cpu-auto-scaling"
  policy_type = "TargetTrackingScaling"
  resource_id = aws_appautoscaling_target.replicas.resource_id
  scalable_dimension = aws_appautoscaling_target.replicas.scalable_dimension
  service_namespace = aws_appautoscaling_target.replicas.service_namespace

  target_tracking_scaling_policy_configuration {

    predefined_metric_specification {
      predefined_metric_type = "RDSReaderAverageCPUUtilization"
    }
    scale_in_cooldown = 300
    scale_out_cooldown = 300
    target_value = 75
  }
}

resource "aws_appautoscaling_target" "replicas" {
  max_capacity = 15
  min_capacity = 1
  resource_id = "cluster:${aws_rds_cluster.example.id}"
  scalable_dimension = "rds:cluster:ReadReplicaCount"
  service_namespace = "rds"
}