0
votes

I have a autoscaling group defined via Cloudformation with this updated policy:

UpdatePolicy:
  AutoScalingRollingUpdate:
    WaitOnResourceSignals: false

The maxSize of the autoscaling group is set to 4. I have a lifecycle hook for starting and stopping instances.

When I uppdate the ASG (for example by changing the AMI in the LaunchConfiguration) it starts new instances before old instances are completely stopped (before the terminating lifecycle hook is finished).

Can I prevent this? Can I tell Cloudformation/The ASG not to start a new instance before the lifecycle hook is finished?

1

1 Answers

0
votes

When I update the ASG (for example by changing the AMI in the LaunchConfiguration) it starts new instances before old instances are completely stopped (before the terminating lifecycle hook is finished).

From the Amazon EC2 Auto Scaling Lifecycle Hooks and Auto Scaling Lifecycle :

Lifecycle hooks enable you to perform custom actions by pausing instances as an Auto Scaling group launches or terminates them.

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.

enter image description here

What you can try doing is, adding a lifecycle hook that pauses the instance while scaling out. In the meanwhile, your lifecycle hook for scale-in will finish its execution and later on pause on your scale-out instance will be released and it will be up. This will surely impact the creation of instances in normal scale-out conditions as your instance creation will be paused but you might utilize it for other activities like an upgrade, deployment, etc.

You can read about Cooldowns and Custom Actions which might also help you.