首页 > 解决方案 > 使用 terraform 创建 Cloud watch 警报并在警报命中时发送通知

问题描述

使用 Terraform 创建 cloudwatch 警报,但在 1:20 遇到错误解析错误:预期 "}" 但发现无效序列 "$" ,如何在维度和警报操作中传递多个变量

variable "sfn_name"         { }
variable "sns_topic"        { }

resource "aws_cloudwatch_metric_alarm" "checkQueueLength" {
  alarm_name = "MonitorQueueLength"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods = "1"
  metric_name = "ExecutionsStarted"
  namespace = "AWS/States"
  period = "2"
  statistic = "Sum"
  threshold = "1"
  dimensions {
    StateMachineArn = "${aws_sfn_activity.${var.sfn_name}.arn}"
    alarm_description = "checkStatesQueueLength"
    actions_enabled = "true"
  }
  alarm_actions = ["${aws_sns_topic.${var.sns_topic}.arn}"]
}

标签: amazon-web-servicesterraform

解决方案


你不会的。相反,您将传入 aws_sfn_activity 和 sns 主题 arn。

variable "sfn_arn"         { }
variable "sns_topic_arn"        { }

resource "aws_cloudwatch_metric_alarm" "checkQueueLength" {
  alarm_name = "MonitorQueueLength"
  comparison_operator = "GreaterThanThreshold"
  evaluation_periods = "1"
  metric_name = "ExecutionsStarted"
  namespace = "AWS/States"
  period = "2"
  statistic = "Sum"
  threshold = "1"
  dimensions {
    StateMachineArn = "${var.sfn_arn}"
    alarm_description = "checkStatesQueueLength"
    actions_enabled = "true"
  }
  alarm_actions = ["${var.sns_topic_arn}"]
}

推荐阅读