Bobcares

Replace unhealthy EC2 instances in Elastic Beanstalk

by | Aug 29, 2021

Wondering how to replace unhealthy EC2 instances in Elastic Beanstalk? We can help you with this!

As a part of our AWS Support Services, we often receive similar requests from our AWS customers.

Today, let’s see the steps followed by our Support Techs to help our customers to replace unhealthy EC2 instances in AWS Elastic Beanstalk.

 

Replace unhealthy EC2 instances in Elastic Beanstalk

 
The Elastic Beanstalk environment’s Auto Scaling group health check configuration is set to the EC2 type which simply performs a status check of EC2 instance by default.

We can use a configuration file to automate the replacement of unhealthy EC2 instances. That is we must change the health check type of the environment’s auto-scaling group from EC2 to ELB by using a .ebextension if we want to automate the replacement of unhealthy EC2 instances.

Now let’s see the steps for changing the health check type of your instance’s Auto Scaling group to ELB by using the configuration file.
 

Change the health check type of your instance’s Auto Scaling group to ELB

 

  1. Firstly, In the root directory of our source bundle, we need to create a folder named .ebextensions.

2. Then we need to create a new .config file. For example:

Example .ebextensions/autoscaling.config
===============================================
Resources:
AWSEBAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
HealthCheckType: ELB
HealthCheckGracePeriod: 300
===============================================

HealthCheckGracePeriod is the time that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that’s come into service.

3. Now create a zip file for our updated application source bundle, and then we need to deploy your application.

Note that we can also deploy your application using eb deploy.

Also, note that the above steps apply to environments with load balancers only.

Confirm that the health check type of Auto Scaling group is set to ELB

  1. Log in to the AWS Management console and then open the Amazon EC2 console.

2. Select Auto Scaling Groups.

3.  Then enter the environment ID of your Auto Scaling group for Filter and then select our Auto Scaling group.

4. Then we need to confirm that the Health Check Type is set to ELB on the Details tab of our Auto Scaling group.

Note the following points:

  • The status checks do not cover the health of our application, server, or any docker containers running on the instance. It covers only an EC2 instance’s health.
  • The load balancer removes the unhealthy instances from its target when the application crashes. However, the Autoscaling group won’t replace that unhealthy instance.
  • We enable the Auto Scaling group to automatically replace the unhealthy instances by changing the health check type from EC2 to ELB. When the health check fails for an instance, it will replace that unhealthy instance.

[Need help with more AWS queries? We’d be happy to assist]

 

Conclusion

 
To sum up, today we discussed the steps followed by our Support Engineers to help our customers to replace unhealthy EC2 instances in Elastic Beanstalk.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.