Home > Software design >  specify serverId in cloud watch alarms
specify serverId in cloud watch alarms

Time:07-28

I am trying to create an alarm for aws transfer family sever's BytesIn metric. If I click on the alarm button near the metric's name:

enter image description here

I am led to the alarm creation page where the namespace, metric name and server id are already specified. However, when I try to create an alarm via terraform, I don't see any argument where I can specify the serverId. So how can I link a particular server to this alarm?

resource "aws_cloudwatch_metric_alarm" "foobar" {
  alarm_name                = "test-alarm"
  comparison_operator       = "LessThanOrEqualToThreshold"
  evaluation_periods        = "2"
  metric_name               = "BytesIn"
  namespace                 = "AWS/Transfer"
  period                    = "3600"
  statistic                 = "Sum"
  threshold                 = "0"
  alarm_description         = "This metric monitors ftp connection"
  insufficient_data_actions = []
}

CodePudding user response:

Based on the AWS documentation for monitoring the Transfer family [1], the ServerId field is what is called a dimension. Since there are no examples for the Transfer family in the Terraform documentation, it might be a bit harder to understand what needs to be done, but there are other examples with dimensions, e.g., for an NLB [2]:

  dimensions = {
    TargetGroup  = aws_lb_target_group.lb-tg.arn_suffix
    LoadBalancer = aws_lb.lb.arn_suffix
  }

Since you have provided most of the requirements, the only thing that is missing is the dimensions block:

resource "aws_cloudwatch_metric_alarm" "foobar" {
  alarm_name                = "test-alarm"
  comparison_operator       = "LessThanOrEqualToThreshold"
  evaluation_periods        = "2"
  metric_name               = "BytesIn"
  namespace                 = "AWS/Transfer"
  period                    = "3600"
  statistic                 = "Sum"
  threshold                 = "0"
  alarm_description         = "This metric monitors ftp connection"
  insufficient_data_actions = []
  
  dimensions = {
    ServerId = "<some server id>"
  }

}

Since you know the value for the ServerId it should not be an issue to add it.


[1] https://docs.aws.amazon.com/transfer/latest/userguide/monitoring.html#metrics

[2] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm#example-of-monitoring-healthy-hosts-on-nlb-using-target-group-and-nlb

  • Related