如果达到生命周期挂钩超时,请勿终止 EC2 实例
Do not terminate EC2 instance if Lifecycle hook timeout is reached
如果用于终止实例的 lambda 耗尽机制未在生命周期挂钩的 cloudformation 中设置的 HeartbeatTimeout 参数内完成,则需要让 EC2 实例 运行。
我有一个 lambda 函数,它会耗尽 EC2 实例并在 cloudformation 中触发缩减警报时终止它。我目前使用 LifeCycle 挂钩来终止我的 cloudformation 中的实例。但是,我知道生命周期挂钩有一个 HeartbeatTimeout 参数,当 lambda 耗尽机制在此期间未完成时,它会终止实例。如果 lambda 无法在 HeartbeatTimeout 内耗尽实例,我不想终止实例,因为仍有任务 运行ning 在这上面。我想中止实例终止并让实例 运行 在这种情况下,有什么办法可以做到这一点吗?
这是 cloudformation 中的 lifecyclehook
"Terminationhook": {
"Type": "AWS::AutoScaling::LifecycleHook",
"Properties": {
"AutoScalingGroupName": { "Ref": "Cluster" },
"DefaultResult": "ABANDON",
"HeartbeatTimeout": "3600",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
"NotificationTargetARN": { "Ref" : "SNSTOPIC"},
"RoleARN": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"DependsOn": "SNSTOPIC"
}
如果 lambda 没有在 3600 秒的 HeartbeatTimeout 内耗尽实例,那么我想中止实例终止
来自Amazon EC2 Auto Scaling Lifecycle Hooks - Amazon EC2 Auto Scaling:
Keeping Instances in a Wait State
Instances can remain in a wait state for a finite period of time. The default is one hour (3600 seconds). You can adjust this time in the following ways:
- Set the heartbeat timeout for the lifecycle hook when you create the lifecycle hook. With the put-lifecycle-hook command, use the
--heartbeat-timeout
parameter. With the PutLifecycleHook
operation, use the HeartbeatTimeout
parameter.
- Continue to the next state if you finish before the timeout period ends, using the complete-lifecycle-action command or the
CompleteLifecycleAction
operation.
- Restart the timeout period by recording a heartbeat, using the record-lifecycle-action-heartbeat command or the
RecordLifecycleActionHeartbeat
operation. This increments the heartbeat timeout by the timeout value specified when you created the lifecycle hook. For example, if the timeout value is one hour, and you call this command after 30 minutes, the instance remains in a wait state for an additional hour, or a total of 90 minutes.
The maximum amount of time that you can keep an instance in a wait state is 48 hours or 100 times the heartbeat timeout, whichever is smaller.
底线:如果您需要更多时间,可以通过记录心跳重新开始超时时间。
如果用于终止实例的 lambda 耗尽机制未在生命周期挂钩的 cloudformation 中设置的 HeartbeatTimeout 参数内完成,则需要让 EC2 实例 运行。
我有一个 lambda 函数,它会耗尽 EC2 实例并在 cloudformation 中触发缩减警报时终止它。我目前使用 LifeCycle 挂钩来终止我的 cloudformation 中的实例。但是,我知道生命周期挂钩有一个 HeartbeatTimeout 参数,当 lambda 耗尽机制在此期间未完成时,它会终止实例。如果 lambda 无法在 HeartbeatTimeout 内耗尽实例,我不想终止实例,因为仍有任务 运行ning 在这上面。我想中止实例终止并让实例 运行 在这种情况下,有什么办法可以做到这一点吗?
这是 cloudformation 中的 lifecyclehook
"Terminationhook": {
"Type": "AWS::AutoScaling::LifecycleHook",
"Properties": {
"AutoScalingGroupName": { "Ref": "Cluster" },
"DefaultResult": "ABANDON",
"HeartbeatTimeout": "3600",
"LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
"NotificationTargetARN": { "Ref" : "SNSTOPIC"},
"RoleARN": {
"Fn::GetAtt": [
"Role",
"Arn"
]
}
},
"DependsOn": "SNSTOPIC"
}
如果 lambda 没有在 3600 秒的 HeartbeatTimeout 内耗尽实例,那么我想中止实例终止
来自Amazon EC2 Auto Scaling Lifecycle Hooks - Amazon EC2 Auto Scaling:
Keeping Instances in a Wait State
Instances can remain in a wait state for a finite period of time. The default is one hour (3600 seconds). You can adjust this time in the following ways:
- Set the heartbeat timeout for the lifecycle hook when you create the lifecycle hook. With the put-lifecycle-hook command, use the
--heartbeat-timeout
parameter. With thePutLifecycleHook
operation, use theHeartbeatTimeout
parameter.- Continue to the next state if you finish before the timeout period ends, using the complete-lifecycle-action command or the
CompleteLifecycleAction
operation.- Restart the timeout period by recording a heartbeat, using the record-lifecycle-action-heartbeat command or the
RecordLifecycleActionHeartbeat
operation. This increments the heartbeat timeout by the timeout value specified when you created the lifecycle hook. For example, if the timeout value is one hour, and you call this command after 30 minutes, the instance remains in a wait state for an additional hour, or a total of 90 minutes.The maximum amount of time that you can keep an instance in a wait state is 48 hours or 100 times the heartbeat timeout, whichever is smaller.
底线:如果您需要更多时间,可以通过记录心跳重新开始超时时间。