Amazon-Web-Services

AWS Autoscaling Group:無效的隊列配置錯誤

  • January 22, 2019

使用 Terraform 在 AWS 中創建 Autoscaling Group。

mixed_instances_policyaws_autoscaling_groupTerraform 的資源中使用。

resource "aws_launch_template" "go_app" {
 image_id               = "${data.aws_ami.go_app.id}"
 instance_type          = "${var.launch_config["instance_type"]}"
 vpc_security_group_ids = ["${aws_security_group.go_app.id}"]
 key_name               = "${var.key_name}"
}

啟動instance_type模板是.t2.small

resource "aws_autoscaling_group" "go_app" {
 name                 = "${aws_launch_template.go_app.name}-asg"
 vpc_zone_identifier  = ["${aws_subnet.public.*.id}"]

 min_size             = 1
 desired_capacity     = 2
 max_size             = 4

 mixed_instances_policy {
   launch_template {
     launch_template_specification {
       launch_template_id = "${aws_launch_template.go_app.id}"
       version            = "$$Latest"
     }
     override {
       instance_type = "t2.micro"
     }
     override {
       instance_type = "t2.nano"
     }
   }

   instances_distribution {
     on_demand_base_capacity                  = 1
     on_demand_percentage_above_base_capacity = 0
     spot_allocation_strategy                 = "lowest-price"
     spot_instance_pools                      = 2
   }
 }
}

這應該創建 1 個按需實例和 1 個 Spot 實例(所需容量為 2)。但它會創建 1 個按需實例,但無法創建 Spot 實例。

AutoScaling 組的 Activity History 提到 AutoScaling 組嘗試創建實例但由於以下錯誤而失敗:

Launching a new EC2 instance. Status Reason: Invalid fleet configuration. 
Overrides t2.nano, us-west-2c, LINUX. Launching EC2 instance failed.

Invalid fleet configuration. Overrides t2.nano錯誤消息表示該t2.nano實例類型不是該區域中支持的 Spot 實例類型。

查看Spot 實例顧問以了解支持的實例類型。

引用自:https://serverfault.com/questions/950162