We have seen that health check attributes specified on the load balancer decide whether the EC2 instance is healthy or not. As soon as a health check has been passed, the load balancer starts sending traffic to the EC2 instances, irrespective of whether the application hosted on the EC2 instances is fully configured and installed or not. Often, deploying code and applications take time, and you do not want the load balancer sending traffic until it is fully ready. There is no way for a load balancer to understand whether the EC2 instances are fully configured during bootstrapping. This is where lifecycle hooks play a major role. Lifecycle hooks give us a way to perform actions before an EC2 instance is in InService state, or before an EC2 instance is in Terminated state.
During an EC2 instance launch time, when you add a lifecycle hook to the Auto...