Tuesday, 30 May 2023

Replacing Unhealthy EC2 Instance in Elastic Beanstalk Environment

 In this article, we will look into how to automate the replacement of EC2 instances in an AWS Elastic Beanstalk environment that are failing Elastic Load Balancer health checks.

By default, 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 instances. This means that if you want to automate the replacement of unhealthy EC2 instances you must change the health check type of the environment’s auto-scaling group from EC2 to ELB by using an .ebextension.

To do this follow the below steps:

Step 1: Navigate to your working directory locally. You can create an .ebextensions folder. In this case, there is already one.

Step 2: Now let’s create a new .config file. We’ll name this autoscaling.config. 

Step 3: Now we’ll edit the autoscaling.config file and enter the following details and save it.

Step 4: Now let’s create a new application source bundle by going back to the root of our working directory. At this point we can deploy the updated source bundle after logging into the AWS Management Console. For this navigate to the Elastic Beanstalk console.

Step 5: Then select the environment. Choose Upload and deploy.

Step 6: Then select Choose file. Browse to the working directory and then select the new zip. Provide a logical Version label and finally Deploy it to your environment.

This can take some time depending on your deployment strategy and now you’ve successfully updated your environment to allow the Elastic Beanstalk environment’s auto-scaling group to automatically replace instances that fail ELB health checks. 

No comments:

Post a Comment