如果我有以下 terraform 和可用的 SNS 主题 ARN,有没有办法将 cloudwatch 通知事件附加到 AWS 在幕后创建的警报?
resource "aws_ecs_service" "service_definition" {
name = "${var.servicename}"
cluster = "${var.name}"
task_definition = "${var.task_definition_arn}"
desired_count = "${var.desired_count}"
deployment_minimum_healthy_percent = "${var.deployment_minimum_healthy_percent}"
ordered_placement_strategy {
field = "attribute:ecs.availability-zone"
type = "spread"
}
}
resource "aws_appautoscaling_target" "ecs_target" {
max_capacity = "${var.container_max_count}"
min_capacity = "${var.desired_count}"
resource_id = "service/${var.clustername}/${var.servicename}"
role_arn = "${var.ecs_iam_role}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
depends_on = ["aws_ecs_service.service_definition"]
}
resource "aws_appautoscaling_policy" "ecs_scale-memory" {
name = "${var.servicename}_scale-memory"
policy_type = "TargetTrackingScaling"
resource_id = "service/${var.clustername}/${var.servicename}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
target_tracking_scaling_policy_configuration {
target_value = "${var.target_container_memory_percent}"
scale_in_cooldown = "${var.target_scalein_cooldown_seconds}"
scale_out_cooldown = "${var.target_scaleout_cooldown_seconds}"
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageMemoryUtilization"
}
}
depends_on = ["aws_appautoscaling_target.ecs_target"]
}
AWS 为跟踪事件创建两个警报:
- TargetTracking-service/clustername/servicename-AlarmHigh-GUID 值
- TargetTracking-service/clustername/servicename-AlarmLow-GUID值
这些具有通过附加的 ecs_target 扩展到所需计数的操作。我只是想为这些附加(通过 Terraform)一个 SNS 通知(就像一个可以为 EC2 扩展事件做的那样)。