使用标签和策略优先级
您可以将标签添加到要进行自动扩展的Amazon EC2实例中,然后使用这些标签在自动扩展组中优先选择实例。 结合使用标签和策略优先级可以解决AWS自动扩展策略冲突的问题。
以下是一个示例,展示如何在自动扩展组中设置标签和策略优先级:
resource "aws_autoscaling_group" "example" {
name = "example_group"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
desired_capacity = 3
min_size = 3
max_size = 3
tag {
key = "Environment"
value = "Production"
propagate_at_launch = true
}
tag {
key = "Application"
value = "Example"
propagate_at_launch = true
}
launch_template {
id = "lt-xxxxxxxx"
version = "$Latest"
overrides = [
{
instance_type = "t2.micro"
},
]
}
lifecycle {
ignore_changes = [launch_template]
}
# Scale up policy with higher priority
scaling_policy {
name = "scale_up_policy"
policy_type = "TargetTrackingScaling"
adjustment_type = "ChangeInCapacity"
estimated_instance_warmup = 300
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
target_value = 80.0
}
priority = 50
}
# Scale down policy with lower priority
scaling_policy {
name = "scale_down_policy"
policy_type = "TargetTrackingScaling"
adjustment_type = "ChangeInCapacity"
estimated_instance_warmup = 300
target_tracking_configuration {
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
target_value =
下一篇:AWS自动扩展策略CLI