Imagine having a blog that is running on a single t2.micro EC2 instance. One day, you publish an article on COVID-19 and it goes viral. Your website also receives a substantial amount of feedback, requests, likes, and shares. Since your website is a t2.micro instance, it could possibly crash due to significant network traffic. What can be done to avoid this situation? This is where the AWS load balancer plays a role. It uses several smaller instances, like t2.micros, and distributes the website traffic amongst t2-micro instances equally.
What is Amazon Load Balancer?
Amazon Load Balancer distributes network traffic across its components like Amazon EC2 instances, AWS Lambda, and containers.
Amazon Load Balancer
Let’s move forward and look at the benefits of using Amazon Load Balancer.
Benefits of Using Amazon Load Balancer
Some of the benefits include:
- It is highly available and distributes website traffic across multiple targets
- It provides high security through user authentication and SSL/TLS decryption features
- It can handle drastic changes in website traffic without human intervention
- It helps improve the visibility of your applications through continuous monitoring and auditing
- It supports hybrid load balancing, which can help when migrating resources to the cloud
Now, let’s have a look at algorithms used for load balancing.
Algorithms Used for Load Balancing
In Amazon Load Balancer, there are a variety of algorithms. Let’s discuss the four primary algorithms, which you can implement to your specific use case.
1. Round Robin Method
This simple algorithm is used to distribute the client’s request across a group of servers. Initially, the client request/traffic is sent to the first available server. After a while, that server is moved to the bottom of the queue. The client request also is sent to each server one by one, based on availability.
2. Least Connection Method
This directs network traffic to the server, and it is specifically used when there is a large number of client requests unevenly distributed between the servers.
3. Least Response Time Method
This directs client requests to the server with the lowest average response time. Moreover, it ensures that the load is balanced adequately among the servers.
4. IP Hash
This uses the client’s IP address to route network traffic to the available backend server.
Demo - Create a Classic Load Balancer
First, launch the EC2 instance and ensure all security groups have access to HTTP 80. Next, install the webserver (such as Apache webserver).
Step 1: Select Load Balancer Type
- Open the Amazon EC2 console and select Region for your load balancer on the navigation panel.
- On the navigation bar, go to -> Load Balancing -> Load Balancers -> Create Load Balancer.
- If you are planning to proceed with Classic Load Balancer, choose the Create option
Create load balancer
Step 2: Define Your Load Balancer
- Provide a basic configuration for your load balancer, such as enter your load balancer name
- In Create LB inside, choose the same network that you selected for your EC2 instance and select the enable advanced VPC connection option.
- In the Available subnets section, select any single available public subnet
- Finally, select Assign Security Groups
Define Load Balancer
Step 3: Assign Security Groups and Health Checks to Your Load Balancer in a VPC
- Select Create a new security group. Enter a name and description for the assigned security group.
- Choose -> Configure Security Settings -> Health Check -> Configure Health Check to continue to the next step.
- On the Configure Health Check page, set Ping Port to 80 and enter single slash “/” in Ping Path.
- Skip the Advanced Details section and select Add EC2 instance.
Step 4: Register EC2 Instance With Your Load Balancer
- Select the instance to register with your load balancer.
- Skip the connection draining enabled option and choose Add Tags (optional)
Step 5: Create and Verify Your Load Balancer
- Select Create on the Review page
- Once the load balancer is created, select your new load balancer
- When an EC2 instance is in service, you should verify the load balancer. Copy the link from DNS name and paste it into the address field of an Internet-connected web browser.
- You will see a default page of your server when your load balancer starts working.
Load Balancer creation - Amazon Load Balancer
Learn about AWS architectural principles and services like IAM, VPC, EC2, EBS and more with the AWS Solutions Architect Course. Register today!
In this introductory article, we discussed what an Amazon Load Balancer is, the benefits and algorithms of Amazon Load Balancer, and we also went through a step-by-by demonstration on how to create an Amazon Load Balancer.
Whether you’re an experienced AWS Architect, or you’re aspiring to break into this exciting industry, enrolling in our Cloud Architect program will help individuals with all levels of experience master AWS Cloud Architect techniques and strategies.
Do you have any questions? Please feel free to leave them in the comments section of this article; our experts will get back to you as soon as possible.