Introduction
Table of Contents
In AWS it’s very easy to Create Auto Scaling with Load Balancer and EC2 Machine.
Load balancing refers to efficiently distributing incoming network traffic
across a group of backend servers, also known as a server farm or server
pool.
In this manner, a load balancer performs the following functions:
Distributes client requests or network load efficiently across multiple
servers.
Types of Load Balancer:
Application Load Balancers.
Network Load Balancers.
Classic Load Balancers.
Amazon ECS services can use either type of load balancer.
Application Load Balancers are used to route HTTP/HTTPS.
What is the Autoscaling Group?
The Autoscaling group contains a collection of Amazons EC2 instance that is treated as a logical grouping for the purpose of automatic scaling and management.
It also enables you to use health check replacement and scaling policies. To create Auto scaling we cave to create the Load balancer.
How to Create Load Balancer?
- Login to AWS as Root user
- In AWS management console go to “services”
- Go to “EC2”
- In EC2 dashboard go to “Load Balancer”

Figure1. EC2 Dashboard locating Load Balancer.

- Click on “Create Load Balancer”

As we learn before we have three types of the Load Balancer, Application Load Balancer, Network Load Balancer, Classic Load Balancer.
Application Load Balancer, Network Load Balancer these balancers need to pay for use.
But for your learning purpose, we go with “Classic Load Balancer”
In Classic Load Balancer click on “Create”

- Give the load balancer name.
- Create LB Instance leave it as default.
- VPC configuration, Internal LB live it unchosen because they will charge.
- Load Balancer Protocol give as HTTP.
- Click on “Next”.

- Assign Security Group to load balancer.
- If you want to create a new security group can select create a group.
- If you want to select from the existing group you can select.
- Click on “Next”.
Health Check Setup

- Health check which your load balancer will automatically perform health checks on your EC2 instances and only route traffic to instances that pass the health check.
- If an instance fails the health check, it is automatically removed from the load balancer. Customize the health check to meet your specific needs.
- Ping protocol as “HTTP”.
- Port “80”.
- Ping path “/healthy.html”.
- In Advanced Details give “Response Timeout”, which is used to set time to the website response.
- “Interval time”, which is used to set time to the website to reload.
- “Unhealthy threshold”, which checks the instance 2 times and the instance is not responding it is not healthy.
- “Healthy threshold”, which checks the instance 3 times by refreshing it if it gives an instant response it is healthy.
- Click on “Next”.
Add EC2 Instances

- Select EC2 instance if you have or other wise we can add it later.
- Click on “Next”.

- Give the tag to the LB.
- Click on “Review and Create”.

- Review the details which you given.
- Click on “Create”.

- The status bar shows 0 of 2 that means there is no instance is running.
- If it shows 2 of 2 it means the instance are in service.
- Let’s check whether the DNS name is working or not.
- Copy it and open in new tab.

- When you reload the page, it will send load equally to EC2 instance.
- To create Autoscaling first we have to launch configuration.
How to Launch AutoScaling Configuration?
- In EC2 dash board go to “Launch Configuration”.


- Click on “Create Launch Configuration”

- Select AMI “Amazon Linux” machine

- Select “t2.micro”.
- Click on “Next”.

- Give the name to the LC (Launch Configuration), remaining live as it is.
- Click on “Advanced Details”.

- Kernel ID keep it default.
- RAM Disk ID keep it default.
- Use Data “write script”, to launch one website.
- IP Address type keep it as default.
- Click on “Next”.

- Add volume to the LC.
- Click on “Next”.

- Give security group to the LC.
- Click on “Review”.

Click on “Create LC”.

- Select keypair already in exist.
- Click on “Create LC”.

- From this we have to “Create Auto Scaling group”.

- Give Group name to ASG.
- Launch configuration which we created before it takes automatically.
- Give Group size means no of instance we want to launch initially.
- Give Network default.
- Give subnet in all regions since we are launching in N.Virginia it contains 6 Availability Zones means it have 6 default subnets.
- We can launch ASG in 6 subnets or we can chose as per your need.
- As per now launch in all subnet because if any region goes down the it send data to another region.
- Click on “Advanced Details”.


- Enable Load Balancing.
- Give Load balancing which you have created, don’t give Target Group.
- Give health check type as “ELB”.
- Give Health check grace period as per your need, remaining leave as it is.
- Click on “Next”.


- Click on “Add Alarm”.

- Click on “Create Topic”.

- This is to increase the instance.
- Give name to the notification.
- Give your email ID.
- Give percentage to the >=50 means when CPU performance is >50 it will stop the instance and create another instance and pass the load to that instance.
- Click on “Create Alarm”.

- We can give Group at its initial size or use scaling policies to adjust the capacity of this group.
- As per now we go with “use scaling policies to adjust the capacity of this group”.
- We can set the scale to instance like minimum 2 instance has to run initially and it can create maximum 6 instance.
- We can set alarm to the instance.
- Now Decrease the instance.
- The process is same as increase group but here we decrease the instance when the performance is low.

- If the CPU performance is less than 3 percent it will delete one instance.
- Click on “Next”.

- Click on “Add Notification”.

- Enable all type of instance actions if any of the type is not working it will send notification.
- Click on “Next”.

- Give tag to ASG.
- Click on “Review”.

- Click on “Create ASG”.

Let’s see the instances are working or not.

- It shows that instances are created by ASG.
- Check-in load balancer whether these instances are working or not.

- Shows the instances are running.
- Now copy the DNS Name and check whether the webpage is opening or not.

- Shows that the webpage is working.
- If we terminate one of the running instances it can create another instance or not.
Let’s terminate instance.


- When we have terminated instance, it terminated in ASG.
- When we terminated it took 1 to 2 minutes and created another instance.
- So, by this, we can say that if any instance is terminated the ASG will create another instance immediately and share the load this will happen when we create an instance with ASG.
- Create Auto Scaling with Load Balancer and EC2 Machine
Conclusion:
By this we came to know how to Create Auto Scaling with Load Balancer and EC2 Machine . Autoscaling is used when instance is overloaded it will create another instance automatically and share the load (for this we attach load balancer in the process of Autoscaling creation) , when the instance is not in use it will shutdown automatically.
Pingback: Enable the Load Balancer Based on Health Check
Pingback: SNS Topic and Subscribe Create a Topic and Subscribe