AWS Autoscaling and Elastic Load Balancing

Srini
7 min readSep 9, 2020

--

This is a part of my learning Journey towards Autoscaling . This is based on the Namrata shah youtube video Here. She is Microsoft Prestigious Most Valuable Professional award (MVP) for two consecutive years and was recognized as Virtual Technology Specialist for BizTalk

Prequisistes : Create Custom VPC as based on the following link

https://medium.com/p/90810966be92

Step 1 — Create EC2 Instance with the following information

Step 2— Install httpd

· Connect to the EC2 machine from terminal window using putty or bash and login as the root user

· Run the following commands

·yum install httpd -y·sudo systemctl enable httpd·sudo systemctl start httpd

Copy the public IP of your EC2 machine and paste in the browser to ensure its working

In the EC2 Instance command window terminal use the following command to create index .html

cd /var/www/htmlvi index.html

Enter any text in the window or as shown in the below, save and exit

This is my Auto scaling and load balance Demo workshop

Now use the following link to ensure it is working

http://ec2 machine publicip address/index.html

You should see the following output

Step 3— Create AMI Image

Image Name: VPC-ASG Demo- Image
Iamge Description: VPC-ASG Demo- Image
Select Create image

Once the image is available, This is our AMI. And this AMI will be used in Load balancing and auo scaling and other EC2 instances

Step 4— Create Application load balancer

Application Load Balancer

Once the Load balancer is created save the DNS url name in the Notepad

Step 5— Create New Security Group for Launch Configuration

In this security group, the port 80 that will be created will be accessible by the security group of your ALB load balancer and Port 22 should be accessible by the security group of the EC2 instance. That is the EC2 instance we created earlier and we used this to create our AMI as well. The reason we are doing that is , the dynamic EC2 instances that are going to be added in your Auto scaling group lets say, those EC2 instances are not going to have public IP address. If you want to connect to those EC2 instances the only way to connect for you is your EC2 instances of your Private IP address. what we can do is we can use the public IP address connect the EC2 host and then from there , connect to our EC2 instances in our Auto scaling group using their Private IP address. Hence this security group is configured in this way. To ensure this security groups are configured correctly, cross check the security settings of this group. Other wise it doesn’t work. The EC2 instances in the auto scaling group will not have public IP address.

Security Group

Step 6— Create Launch Configurations

Step 7— Create Auto Scaling Group

We are interested in is essentially our Auto scaling activity history . This is where you will see that the auto scaling group is working or not. Weather its truely in action. You see in the activity history it launched the EC2 instance.

Right now the configuration of auto scaling group is as follows. The desired number, minimum and maximum also 1 here. So this particular auto scaling group has currently have one instance in it. That is because the configuration parameters are set like that.

If request comes in, it will comes in, it will comes to your load balancer because we will be accessing our application using the DNS of our load balancer. And that load balancer will direct the request to one of the EC2 instances. Right now there is only one EC2 instance. So the request will be directed to that instance. The request will come in and it will go to the load balancer and the load balancer will directed to your EC2 instance over here.

Let us see if the health check was successful. Remember we did not register any target for the target group. So this target has now been associated to this target group dynamically. Remember when creating auto scaling we had basically selected our target group. Now this has been associated over here dynamically and health check is successful .

Now instead accessing the index.html through EC2 instance. Lets acess my application using ELB instance

As you see I am able to access my application using the application load balancer DNS and basically I send the request over internet, It went to the application load balancer that redirected it the EC2 instance. so one single EC2 instance that is available in the auto scaling group. So the application load balancer is currently there in picture.

If there are more instances which we will see now, because the auto scaling group is going to be scale in and scale out. This particular request that I am going to send in future it will go to the application load balancer will be dynamically router to the EC2 instances in the auto scaling group

Right Now in my auto scaling group I have one instance. If you go ahead and click on → Edit

Lets change the desired capacity to 2 and Max capacity to 3 as shown below and default cool down to 10 seconds and click Update

You will see there will be now two instances running to match the desired capacity. Here we manually triggered auto scaling .

Once the instance is going to be in service, it will take some time and you will see the auto balancing will trigger as well as elastic load balancer of my request will be triggered automatically. I will not know to what Instance my request is being sent to .

Lets go the target groups and see the health status of the new EC2 instance that is created . From below image it shows both are healthy.

If you want to see this auto scaling happening just how it happen in real life, if you go back and look into the scaling policy over here, the scaling policy that we have created depending upon the number of request that the application load balancer receives per target that is per instance if that goes beyond 1.

That mean more than one request per target, it will basically trigger auto scaling. If the number of request per target goes up then the number of instances over here will increase. The only way to do is to increase the number of request.

In the below image you see the number of users target is more than 1, you observe there is one more instance in the in progress to match the request of maximum instances that is three

Depending upon the number of load, it will reduce the number of EC2 instances. Here below images shows the EC2 instance is getting terminated and waiting for the connection to drain

To terminate all instance, select all the fields (Desired,max and min) to zero and update

--

--

No responses yet