Lifecycle Hooks
Last updated
Last updated
Lifecycle hooks enable you to perform custom actions by pausing instances as an Auto Scaling group launches or terminates them.
When an instance is paused, it remains in a wait state either until you complete the lifecycle action using the complete-lifecycle-action command or the CompleteLifecycleAction
operation, or until the timeout period ends (one hour by default).
For example, your newly launched instance completes its startup sequence and a lifecycle hook pauses the instance.
While the instance is in a wait state, you can install or configure software on it, making sure that your instance is fully ready before it starts receiving traffic.
For another example of the use of lifecycle hooks, when a scale-in event occurs, the terminating instance is first deregistered from the load balancer (if the Auto Scaling group is being used with Elastic Load Balancing).
Then, a lifecycle hook pauses the instance before it is terminated.
While the instance is in the wait state, you can, for example, connect to the instance and download logs or other data before the instance is fully terminated.
This shows the transitions between instance states in this process: