amazon-web-servicesterraformamazon-cloudfrontamazon-cloudwatch-metrics

How to create Cloudfront Console Alarm Terraform


Create a cloudwatch alarm:

resource "aws_cloudwatch_metric_alarm" "cloudfront-500-errors" {
  alarm_name          = "${var.ENVIRONMENT_NAME}-AWS-CloudFront-High-5xx-Error-Rate"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods  = 1
  metric_name         = "5xxErrorRate"
  namespace           = "AWS/Cloudfront"
  period              = 60
  statistic           = "Average"
  threshold           = 5
  treat_missing_data  = "notBreaching"
  alarm_actions       = [aws_sns_topic.my-sns-topic.arn]
  actions_enabled     = true

  dimensions = {
    DistributionId = aws_cloudfront_distribution.this.id
    Region         = "Global"
  }
}

I can create an alarm for cloudwatch in terraform, but how do I get the alarm here in "Cloudfront" ?

enter image description here


Solution

  • The answer to this question is that, this UI is really just a link to the cloudwatch metrics. The real issue is my namespace was:

     namespace           = "AWS/Cloudfront"
    

    and it needed to be :

     namespace           = "AWS/CloudFront"