Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
设置您的 Amazon A EC2 uto Scaling 组,以便在终止生命周期操作失败时保留实例。
要在 Auto Scaling 组中使用实例生命周期策略,还必须配置终止生命周期挂钩。如果您配置了实例生命周期策略,但没有任何终止生命周期挂钩,则该策略无效。实例生命周期策略仅在终止生命周期操作被放弃时适用,而当终止生命周期操作成功完成并CONTINUE产生结果时不适用。
实例生命周期策略使用保留触发器来确定何时保留实例。在几种情况下,TerminateHookAbandon触发器会导致留存:
-
当你使用ABANDON结果明确调用 CompleteLifecycleActionAPI 时。
-
当具有默认结果ABANDON的终止生命周期操作因未收到心跳超时而达到心跳超时时。
-
当终止生命周期操作达到全局超时时ABANDON,默认结果为 48 小时或心跳超时的 100 倍,以较小者为准
- Console
-
配置实例保留
-
打开 Amazon A EC2 uto Scaling 控制台
-
创建您的 Auto Scaling 组(实例生命周期策略默认为终止)
-
前往您的 Auto Scaling 组详情页面,然后选择实例管理选项卡
-
在生命周期挂钩的实例生命周期策略中,选择 Reta in
-
使用以下方法创建终止生命周期挂钩:
- Amazon CLI
-
配置实例保留
将create-auto-scaling-group命令与实例生命周期策略一起使用:
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-template LaunchTemplateName=my-template,Version='$Latest' \
--min-size 1 \
--max-size 3 \
--desired-capacity 2 \
--vpc-zone-identifier subnet-12345678 \
--instance-lifecycle-policy file://lifecycle-policy.json
lifecycle-policy.json 的内容:
{
"RetentionTriggers": {
"TerminateHookAbandon": "retain"
}
}
添加终止生命周期钩子
使用 put-lifecycle-hook 命令:
aws autoscaling put-lifecycle-hook \
--lifecycle-hook-name my-termination-hook \
--auto-scaling-group-name my-asg \
--lifecycle-transition autoscaling:EC2_INSTANCE_TERMINATING \
--default-result ABANDON \
--heartbeat-timeout 300