AWS autoscaling group: Wait for first instance to finish before scaling-out again

54 Views Asked by At

I have a requirement when using AWS autoscaling groups:

  • I need to wait for the first instance to finish installation of software packages before the autoscaling group spins up subsequent instance.
  • The installation of the first instance will take hours
  • The installation completes when the service starts and the service is using a certain port (eg. service is running on port 123)

How am I able to set up this?

1

There are 1 best solutions below

0
John Rotenstein On

From Amazon EC2 Auto Scaling lifecycle hooks - Amazon EC2 Auto Scaling:

Amazon EC2 Auto Scaling offers the ability to add lifecycle hooks to your Auto Scaling groups. These hooks let you create solutions that are aware of events in the Auto Scaling instance lifecycle, and then perform a custom action on instances when the corresponding lifecycle event occurs. A lifecycle hook provides a specified amount of time (one hour by default) to wait for the action to complete before the instance transitions to the next state.

As an example of using lifecycle hooks with Auto Scaling instances:

  • When a scale-out event occurs, your newly launched instance completes its startup sequence and transitions to a wait state. While the instance is in a wait state, it runs a script to download and install the needed software packages for your application, making sure that your instance is fully ready before it starts receiving traffic. When the script is finished installing software, it sends the complete-lifecycle-action command to continue.

Thus, you could configure a Lifecycle Hook that waits for your newly-launched instance to signal back that it is ready. That instance will then be added to the Auto Scaling group.

However, I'm not sure whether you can prevent another scale-out event during this time.