LoginSignup
0
0

AWS Terraform - ECS Fargate の Auto Scaling > スケーリングポリシー > ターゲットの追跡

Last updated at Posted at 2023-09-25

やりたいこと

この左の「ターゲットの追跡」の設定をTerraformで管理したい

image

コード例

Auto Scaling のターゲットとポリシーを作れば良いようだ

resource "aws_appautoscaling_target" "xxx" {
  service_namespace  = "ecs"
  scalable_dimension = "ecs:service:DesiredCount"
  resource_id        = "service/<クラスタ名>/<サービス名>"
  min_capacity       = 1
  max_capacity       = 15
}

resource "aws_appautoscaling_policy" "yyy" {
  name               = "cpu-auto-scaling"
  service_namespace  = aws_appautoscaling_target.xxx.service_namespace
  scalable_dimension = aws_appautoscaling_target.xxx.scalable_dimension
  resource_id        = aws_appautoscaling_target.xxx.resource_id
  policy_type        = "TargetTrackingScaling"

  target_tracking_scaling_policy_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ECSServiceAverageCPUUtilization"
    }

    target_value       = 75
    scale_in_cooldown  = 300
    scale_out_cooldown = 300
  }
}

predefined_metric_type にはこのCPU/Memory/ALBRequestの3種類のどれかを指定する

image.png

Note

このTerraformの例でも自動的にCloudWatchアラームが作成されるようだ
(Alarm-HighとAlarm-Lowの2種類)

公式

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0