0

I have an Autoscaling Group behind an Application Load Balancer. Both of them are configured to use 2 subnets for 2 different AZ.

The Autoscaling Group is set to provision only 1 instance (min:1, max: 1, desired: 1)

Now in case of AZ failure the Load balancer will detect that the instance is Unhealthy and stop sending tarfic to it.

But i assume that the Autoscaling Group will consider the instance as Healthy, so it will not create a new instance in the second AZ.

So my question is there a way to make the Loadbalancer to notify the autoscaling group to terminate the instance in the failed AZ and to start a new one in the ok AZ ?

I now that the best practice is to set the Autoscaling group to provision for example 2 instances, one in each AZ. But is there a way to make it work with only 1 instance ?

Thanks.

user1297406
  • 1,241
  • 1
  • 18
  • 36

1 Answers1

2

ASG has two options for health checks. By default, it uses EC2 health checks. But since you are using ALB, you should set ASG to use ALB health checks (in addition to EC2 health checks).

This way if ALB determines that your instance is unhealthy for whatever reason, ASG will also consider is as unhealthy.

There are also custom health checks, but in your case, using ALB health checks should be sufficient.

More is here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/healthcheck.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-recover.html

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Thank you i tried that and yes now the ASG is detecting that the instance is unhealthy. But the problem is that it's trying again and again to recreate the new instance in the same faulty AZ (i simulated an AZ failure by blocking all access in the NACL) – user1297406 Mar 06 '20 at 14:31
  • UPDATE : now after aboute 30mn the ASG finally created the new instance in the working AZ. Is there a way to make it do that once it detects an unhealthy instance ? – user1297406 Mar 06 '20 at 14:45
  • @user1297406 You want to make it faster? You have to use detailed monitoring (1 min intervals), not default one (5 minutes). – Marcin Mar 06 '20 at 22:07
  • By Faster i mean by creating directly the new instance in the working AZ – user1297406 Mar 08 '20 at 19:49
  • Is there a way to make the ASG do that ? – user1297406 Mar 10 '20 at 08:55
  • @user1297406 Do what? ASG automatically replaces unhealthy instances. – Marcin Mar 10 '20 at 08:56
  • Yes but it's continuosly replacing it in the Failed AZ. After many retries it finally create the new instance in the Wokring AZ – user1297406 Mar 10 '20 at 10:58
  • @user1297406 You can't control which AZ will be chosen from those you have specified for the ASG. AWS does zone re-balancing, and it puts your instance where it suits it most. – Marcin Mar 10 '20 at 11:02