Open akshayvvr opened 3 years ago
Creating alarms for Synthetics Canaries via the AWS Console is described here.
@akshayvvr Thanks for raising this issue.
The CloudWatch Alarms associated with a Canary when created via the AWS Console are not specified in the CreateCanary API and so are not part of the aws_synthetics_canary
resource.
To associate alarms with the canary you will need to use the aws_cloudwatch_metric_alarm
resource with one or more of the CloudWatch Metrics published by the canary.
Creating alarms for Synthetics Canaries via the AWS Console is described here.
@akshayvvr Thanks for raising this issue. The CloudWatch Alarms associated with a Canary when created via the AWS Console are not specified in the CreateCanary API and so are not part of the
aws_synthetics_canary
resource. To associate alarms with the canary you will need to use theaws_cloudwatch_metric_alarm
resource with one or more of the CloudWatch Metrics published by the canary.
Yes, That is correct. Right I use the Synthetics namespace that is auto published. But still, on the canary console, It doesn't show up as an alarm is associated with the Canary.
You need to name alarm like Synthetics-Alarm-canary_name and in this case it will be displayed on canary console
I first created CloudWatch alarms via the console, then manually imported them into Terraform (to make sure the metrics, periods, etc. were set correctly). Here are the corresponding three CloudWatch alarms in Terraform:
resource "aws_cloudwatch_metric_alarm" "duration_alarm" {
alarm_name = "Synthetics-Alarm-${aws_synthetics_canary.this.name}-Duration"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "Duration"
namespace = "CloudWatchSynthetics"
period = 300
statistic = "Average"
threshold = 30000
alarm_description = "Synthetics alarm metric: Duration GreaterThanThreshold 30000"
insufficient_data_actions = []
treat_missing_data = "breaching"
dimensions = {
CanaryName = aws_synthetics_canary.this.name
}
alarm_actions = [
aws_sns_topic.duration_alarm.arn,
]
ok_actions = [
aws_sns_topic.duration_alarm.arn,
]
tags = var.tags
}
resource "aws_cloudwatch_metric_alarm" "success_alarm" {
alarm_name = "Synthetics-Alarm-${aws_synthetics_canary.this.name}-SuccessPercent"
alarm_description = "Synthetics alarm metric: SuccessPercent LessThanThreshold 90"
comparison_operator = "LessThanThreshold"
evaluation_periods = 1
metric_name = "SuccessPercent"
namespace = "CloudWatchSynthetics"
period = 300
statistic = "Average"
threshold = 90
insufficient_data_actions = []
treat_missing_data = "breaching"
dimensions = {
CanaryName = aws_synthetics_canary.this.name
}
alarm_actions = [
aws_sns_topic.success_alarm.arn,
]
ok_actions = [
aws_sns_topic.success_alarm.arn,
]
tags = var.tags
}
resource "aws_cloudwatch_metric_alarm" "failed_alarm" {
alarm_name = "Synthetics-Alarm-${aws_synthetics_canary.this.name}-Failed"
alarm_description = "Synthetics alarm metric: Failed GreaterThanOrEqualToThreshold 1"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
metric_name = "Failed"
namespace = "CloudWatchSynthetics"
period = 900
statistic = "Sum"
threshold = 1
insufficient_data_actions = []
treat_missing_data = "notBreaching"
dimensions = {
CanaryName = aws_synthetics_canary.this.name
}
alarm_actions = [
aws_sns_topic.failed_alarm.arn,
]
ok_actions = [
aws_sns_topic.failed_alarm.arn,
]
tags = var.tags
}
Community Note
Description
At present, it would appear the AWS Provider does not support the ability to set alarms for aws_synthetics_canary resources. This feature would make it much easier to create, associate alarms and notify stakeholders when there is an outage.
New or Affected Resource(s)
Potential Terraform Configuration
References