首页 > 解决方案 > 扩展成功后 AWS AutoScaling Down 策略失败:无法执行自动扩展操作:未找到指标值的步进调整

问题描述

在 Terraform v13 中创建自动缩放策略和 cloudwatch 警报资源时,它们可以正常创建。但是,在对端点进行负载测试时,它们成功地扩展了实例,但是当 CPU 利用率在一段时间内达到必要的百分比时无法缩减。错误如下所示:

“historySummary”:“未能执行 AutoScaling 操作:未找到度量值 [5.99763732496649, 2.7634547331059975] 和违规增量 -4.00236267503351 的步进调整”

下面列出的是 terraform 资源:

自动扩缩政策 -

resource "aws_appautoscaling_policy" "frontend_down" {
  name               = "${var.name}_frontend_scale_down"
  service_namespace  = "ecs"
  resource_id        = "service/${aws_ecs_cluster.main.name}/${aws_ecs_service.frontend.name}"
  scalable_dimension = "ecs:service:DesiredCount"

  step_scaling_policy_configuration {
    adjustment_type         = "ChangeInCapacity"
    cooldown                = 30
    metric_aggregation_type = "Maximum"

    step_adjustment {
      metric_interval_lower_bound = 0
      scaling_adjustment          = -1
    }
  }

  depends_on = [aws_appautoscaling_target.frontend_target]
}

Cloudwatch 警报 -

resource "aws_cloudwatch_metric_alarm" "frontend_service_cpu_low" {
  alarm_name          = "${var.name}_cpu_utilization_low_fe"
  comparison_operator = "LessThanOrEqualToThreshold"
  evaluation_periods  = "2"
  metric_name         = "CPUUtilization"
  namespace           = "AWS/ECS"
  period              = "60"
  statistic           = "Average"
  threshold           = "10"

  dimensions = {
    ClusterName = var.ecs_cluster_name
    ServiceName = var.ecs_service_name_frontend
  }

  alarm_actions = [var.autoscaling_down_arn_frontend]

  tags = {
    Name        = "${var.name}-autoscaling"
    BillingCode = var.billing_code_tag
    Environment = var.environment_tag
  }
}

标签: javascriptamazon-web-servicesterraformamazon-cloudwatchautoscaling

解决方案


找出原因,这是因为在缩减策略时我使用的是“metric_interval_lower_bound”而不是“metric_interval_upper_bound”。当按比例缩小时,与警报阈值和 cloudwatch 指标相比,它提供负增量,因此 0 成为上限。放大时,您使用下限,因为它提供正增量


推荐阅读