Load balancers are a beneficial technology since they increase the availability of any web-based application or website.
For example, when multiple clients attempt to access your web application, they may not be able to reach it if the number of accessors is very high.
Here’s where load balancers step in.
They act as distributors, dispensing the incoming traffic across many targets (for example, Amazon EC2 instances, IP addresses, containers, etc.). In this blog, we will discuss how to create Network and Application Load Balancers in AWS.
So without any further ado, let’s dive right in!
What is a Network Load Balancer?
A Network Load Balancer (NLB) works at layer 4 of the Network Protocol. It can handle both TCP and UDP, as well as TCP connections encrypted with TLS.
Its main feature is high performance. Also, it uses static IP addresses and can be assigned Elastic IPs—not possible with ALB (Application Load Balancer) or ELB (Elastic Load Balancing).
If you are using container services and/or want to support more than one port on an EC2 instance, NLB is especially well suited to ECS (The Amazon EC2 Container Service). On that note, let’s find out how to create a Network Load Balancer.
How to Create a Network Load Balancer in AWS?
Follow these steps to create a Network Load Balancer in AWS.
Step 1: Log in to the console https://console.aws.amazon.com/ec2/.
Step 2: In the left navigation panel, under Load Balancing, choose Target Groups.
Step 3: Click on create Target Group. Over there, you can select the target type. Select Instance to specify targets by instance ID or IP addresses to specify targets by IP address.
Step 4: Next, enter a name for your Target group and select the protocol. Here we are using TCP with port 80. There are other protocols as well. Below are some of them:
- If the listener protocol is TCP, choose TCP or TCP_UDP.
- If the listener protocol is TLS, select TCP or TLS.
- If the listener protocol is UDP, select UDP or TCP_UDP.
- If the listener protocol is TCP_UDP, choose TCP_UDP.
Step 5: Select the Virtual Private Cloud you want to use. Then enable Health check protocol like TCP, and click on Next.
Step 6: Now, you can register the Target as shown below.
Step 7: Since we have selected an IP as the target, you must enter an IP from your VPC and click on create. The Target Group will be listed below.
Now you have created a network load balancer. It’s time to configure it and the listener!
Configuring A Network Load Balancer And A Listener
These are the steps to configure a network load balancer and its listener.
Step 1: Log in to the console (https://console.aws.amazon.com/ec2/).
Step 2: In the navigation pane, under Load Balancing, choose Load Balancers.
Step 3: Click on create Load balancer and select load balancer type. As we are working on a Network Load Balancer, select it and hit Create.
Step 4: Enter the Network Load Balancer name. Select the scheme, whether it’s internal or Internet-facing. Here we are selecting Internal as the project requires it.
Step 5: The next stage is network mapping. So select the VPC and the Availablity zone as the NLB is internal. Select subnets that are not public-facing.
Step 6: The last step is to configure the listeners and routing. Select the protocol and the port followed by the Target group.
Step 7: Click on create. Provisioning may take some seconds.
We have completed setting up the Network Load Balancer in AWS!
Now let’s look into how to set up the Application Load Balancer.
What is an Application Load Balancer?
An Application Load Balancer functions at the Application layer of the Open Systems Interconnection (OSI) model.
After the Application load balancer receives a request, it evaluates the listener rules in priority order to determine which rule to apply. Then it selects a target from the target group for the rule action.
How to Create Application Load Balancer?
Here’s how to create an application load balancer.
Step 1: Log in to the console (https://console.aws.amazon.com/ec2/ )
Step 2: In the left navigation panel, under Load Balancing, select Load balancers. Then, choose Application Load Balancer.
Step 3: Now, you can start with basic configuration by setting a name for your Application Load Balancer, selecting whether it is internet facing or internal, and the IP address type.
Here, we are using the internet-facing scheme as we want the ALB to connect to the internet.
Step 4: Next is to set up the Listeners. A listener is a process that checks for connection requests using the protocol and port that you configured.
Step 5: Set up an Available Zone for your ALB, including selecting your VPC, Availability zone, and subnets.
Step 6: After that, you will go through the Configure Security Settings and set the security group you should maintain to add more security for your ALB.
Step 7: Now, let’s set up a Target group for your ALB. This is almost the same as what did for NLB previously.
Step 8: Here, you have to mention the name of your Target Group. Select the Target type. We have 3 options—Set Instance as Target, IP, and Lamba. We are using an instance here.
Step 9: Set up the protocol, port, and protocol version.
Step 10: Another essential part of this Application Load Balancer is a Health Check. For Health checks, keep the default health check settings, or you can change the path and protocol according to your application.
Step 11: The last part of the configuration is configuring targets for the target group. To register targets by instance ID, follow these steps.
Step 10: For Instances, select one or more instances. Enter the instance listener port, and then choose to Add to register. Next is to create. On the Review page, choose to Create. After the load balancer is configured, choose Close.
We have successfully set up the Application Load Balancer!
Wrapping Up
That was all about how to create a Network and Application Load Balancer in AWS. These can handle several workloads and scale millions of requests in one second. Therefore, they are pretty helpful for those applications or websites that have a lot of visitors.
At SysAlly, we experiment with Cloud and the most useful information is passed on to the world as blogs. Signup for the updates.
Until later, here’s SysAlly signing off!