AWS

[Terraform] ECS Application AutoScaling

AWS

 

24:00にリフレッシュさせる

example_app.tfvars

ENV_VALUE_ENVIRONMENT = "develop"
sample_app_ecs_service_max_capacity       = 4
sample_app_ecs_service_min_capacity       = 2

 

 

example_app.variables

variable "ENV_VALUE_ENVIRONMENT" {}
variable "sample_app_ecs_service_max_capacity" {}
variable "sample_app_ecs_service_min_capacity" {}

 

 

resource "aws_appautoscaling_target" "example_app" {
  service_namespace  = "ecs"
  resource_id        = "service/${module.example-app.aws_ecs_cluster_example_app_name}/${module.example-app.aws_ecs_service_example_app_name}"
  scalable_dimension = "ecs:service:DesiredCount"
  role_arn           = module.iam.ecs_service_role_arn
  min_capacity       = 2  # 初期値。スケールする時はAWSコンソールのECS Serviceから更新してください
  max_capacity       = 10 # 初期値。

  lifecycle {
    ignore_changes = [
      role_arn,
      min_capacity,
      max_capacity
    ]
  }
}

resource "aws_appautoscaling_scheduled_action" "example_app_scale_out" {
  name               = "${var.example_app_prefix}-reflesh-scale-out-${var.ENV_VALUE_ENVIRONMENT}"
  service_namespace  = "${aws_appautoscaling_target.example_app.service_namespace}"
  resource_id        = "${aws_appautoscaling_target.example_app.resource_id}"
  scalable_dimension = "${aws_appautoscaling_target.example_app.scalable_dimension}"
  schedule           = "cron(0 15 ? * MON-SUN *)"

  scalable_target_action {
    min_capacity = "${var.example_app_ecs_service_max_capacity}"
    max_capacity = "${var.example_app_ecs_service_max_capacity}"
  }
}
resource "aws_appautoscaling_scheduled_action" "example_app_scale_in" {
  name               = "${var.example_app_prefix}-reflesh-scale-in-${var.ENV_VALUE_ENVIRONMENT}"
  service_namespace  = "${aws_appautoscaling_target.example_app.service_namespace}"
  resource_id        = "${aws_appautoscaling_target.example_app.resource_id}"
  scalable_dimension = "${aws_appautoscaling_target.example_app.scalable_dimension}"
  schedule           = "cron(15 15 ? * MON-SUN *)"

  scalable_target_action {
    min_capacity = "${var.example_app_ecs_service_min_capacity}"
    max_capacity = "${var.example_app_ecs_service_min_capacity}"
  }
}
resource "aws_appautoscaling_scheduled_action" "example_app_scale_in_modify_max_capacity" {
  name               = "${var.example_app_prefix}-reflesh-scale-in-modify-max-capacity-${var.ENV_VALUE_ENVIRONMENT}"
  service_namespace  = "${aws_appautoscaling_target.example_app.service_namespace}"
  resource_id        = "${aws_appautoscaling_target.example_app.resource_id}"
  scalable_dimension = "${aws_appautoscaling_target.example_app.scalable_dimension}"
  schedule           = "cron(20 15 ? * MON-SUN *)"

  scalable_target_action {
    min_capacity = "${var.example_app_ecs_service_min_capacity}"
    max_capacity = "${var.example_app_ecs_service_max_capacity}"
  }
}

 

 

 

 

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)