如何使用 Amazon Web Services 控制 AutoScalingGroup 删除哪些 EC2 实例?

How can I control which EC2 instances get removed by an AutoScalingGroup using Amazon Web Services?

我已经预见到我的应用程序可能会出现问题,但我不确定是否可以解决,也许需要重新设计架构。

我在 AWS 上使用 AutoScalingGroup (ASG) 创建 EC2 实例来托管玩家可以加入的游戏服务器。目前,ASG 是通过配对 API 手动缩放的,它会根据需要更改所需的容量。游戏服务器结束时出现问题。

当游戏结束时,它会向匹配器发出结束并需要终止的信号,然后匹配器会相应地缩小 ASG,但是,它似乎并不知道要删除哪个实例,并且它不一定是需要终止的那个。

我可以终止该实例,但由于实例终止时 ASG 所需容量永远不会改变,因此会创建另一个服务器。

有没有办法缩减 ASG,以及指定要从组中删除哪些服务器?

最旧的服务器已删除。如果您想缩减特定服务器,则必须在更改所需容量之前关闭该服务器。

简而言之,缩小期间的默认终止策略旨在删除使用最旧启动配置的实例。

目前,Amazon EC2 Auto Scaling 支持以下终止策略:

OldestInstance Terminate the oldest instance in the group. This option is useful when you're upgrading the instances in the Auto Scaling group to a new EC2 instance type. You can gradually replace instances of the old type with instances of the new type.

NewestInstance Terminate the newest instance in the group. This policy is useful when you're testing a new launch configuration but don't want to keep it in production.

OldestLaunchConfiguration Terminate instances that have the oldest launch configuration. This policy is useful when you're updating a group and phasing out the instances from a previous configuration.

ClosestToNextInstanceHour Terminate instances that are closest to the next billing hour. This policy helps you maximize the use of your instances and manage your Amazon EC2 usage costs.

Default Terminate instances according to the default termination policy. This policy is useful when you have more than one scaling policy for the group.

实例保护

可能的解决方案之一是使用实例保护。 auto-scaling 提供实例保护,控制在scaling-in.

时是否可以终止实例

因此,默认情况下,为 ASG 启用实例保护 以保护实例免受 scaling-in 的影响。完成服务器后,减少所需实例数的值,从特定实例中删除实例保护(使用 CLI 或 SDK;请注意,此保护对其余实例保持启用状态)并且 auto-scaling 将终止确切的例子。

有关实例保护的详细信息,请参阅Instance Protection