Create an AWS Load Balancer

Key takeaways:

  • Elastic Load Balancers distribute traffic across multiple EC2 instances, increasing application availability.

  • Before creating a load balancer, configure a target group to route traffic to registered targets like EC2 instances.

  • Create a target group with the desired protocol (e.g., TCP) and health checks to monitor the target’s health.

  • Network Load Balancers (NLBs) handle TCP/UDP traffic (layer 4), while Application Load Balancers (ALBs) handle HTTP/HTTPS traffic (layer 7).

  • To create an NLB, map it to a VPC, select availability zones, and configure listeners with the appropriate protocol and port settings.

  • Effective configuration ensures high traffic management and application performance.

Elastic Load Balancers serve as a single point of contact and help distribute incoming traffic across multiple EC2 instances, IP addresses, or containers, which increases the availability of our applications. AWS supports Network and Application Load Balancers and uses target groups to route the requests it receives.

Network Load Balancers work on the fourth layer of the OSI model and handle TCP/UDP traffic, whereas Application Load Balancers work on the seventh layer and handle HTTP/HTTPS traffic. Load balancers use listeners that check for connection requests using the port and protocol defined in their target group.

Types of load balancers
Types of load balancers

Let’s assume our application has been deployed on an EC2 Instance on port 6000 and needs a load balancer to distribute the traffic it receives.

Create a target group

Before we create a load balancer, we need to configure a target group. A load balancer forwards the requests it receives to target groups, which then route them to registered targets such as EC2 instances using the port and protocol defined in the target group.

Working of a load balancer
Working of a load balancer

Follow the steps given below to create a target group:

  • On the AWS Management Console, use the search bar to type “EC2” and select the “EC2” service.

  • Select “Target Groups” from the left navigation menu, and click the “Create target group” button.

  • In the “Basic configuration” section, select the target type. For this demo, we’ll select “Instances,” assuming our application has been deployed on an EC2 instance.

  • Set the name of the target group to demo-nlb-target-group.

  • Select “TCP” from the drop-down menu under “Protocol” and set the “Port” to 6000, as our application is deployed on this port.

  • Ensure “IPv4” is selected as the IP address type.

  • Select the VPC where your targets have been launched.

  • In the “Health checks” section, select “TCP” as the “Health check protocol.”

  • In the “Advanced health check settings” section, select “Override” and provide 6000 as the “Health check port.” This is the port that will be pinged to check the health of the registered targets.

  • Keep the default settings for all other options and click the “Next” button.

  • Select the instance where our application has been deployed from the “Available instances” section and click the “Include as pending below” button.

  • Click the “Create target group” button.

canvasAnimation-image
1 of 6

Create a load balancer

We’ll create a Network Load Balancer as we have created a target group using the TCP protocol. If you want to create an Application Load Balancer, ensure you’ve configured the correct protocol in the target group. Follow the steps below to create an NLB:

  • On the EC2 dashboard, select “Load Balancers” from the left navigation menu and click the “Create load balancer” button.

  • Click the “Create” button in the “Network Load Balancer” section.

  • Set the name of the load balancer to demo-nlb.

  • Select “Internal” as the “Scheme” and ensure “IPv4” is selected as the IP address type.

  • In the “Network mapping” section, do the following:

    • Select the VPC where our targets have been launched.

    • Select the availability zone for us-east-1a under “Mappings.” Each mapping corresponds to a separate subnet in a different availability zone. The load balancer will route traffic to targets within the selected availability zone and subnet.

  • In the “Security groups” section, remove any preselected security groups. In this step, you can also provide a security group if you’d like, to ensure your load balancer is not accessed by unwanted traffic.

  • In the “Listeners and routing” section, do the following:

    • Ensure “TCP” is selected as the protocol.

    • Set the port to 6000.

    • Select the target group we created from the drop-down menu available under the “Default action” option.

  • Keep the default settings for all other options and click the “Create load balancer” button.

canvasAnimation-image
1 of 4

Conclusion

In this Answer, we learned how Elastic Load Balancers function as a crucial component in distributing traffic and enhancing the availability of applications deployed on AWS. We explored the differences between Network Load Balancers and Application Load Balancers, how to create a target group, and the steps to configure a Network Load Balancer. By following these procedures, we can ensure effective application traffic management while maintaining high availability and performance.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


Which load balancer is best in AWS?

The best load balancer in AWS depends on your use case. Application Load Balancers (ALB) are ideal for HTTP/HTTPS traffic, Network Load Balancers (NLB) are best for handling high-performance TCP/UDP traffic, and Gateway Load Balancers work well for managing third-party virtual appliances.


What are the 3 types of load balancers in AWS?

AWS offers three types of load balancers:

  • Application Load Balancer (ALB): For HTTP/HTTPS traffic at the application layer
  • Network Load Balancer (NLB): For TCP/UDP traffic at the transport layer
  • Gateway Load Balancer (GWLB): For deploying and managing virtual appliances

Should I use ALB or NLB?

You can use ALB if your application is based on HTTP/HTTPS and requires advanced routing features, such as path-based or host-based routing. You can choose NLB for low-latency, high-performance traffic that uses TCP/UDP.


Is Kubernetes a load balancer?

Kubernetes is not a load balancer but integrates with load balancers like ALB or NLB. It uses Service objects to route traffic and can automatically create an external load balancer when using cloud services like AWS.


Free Resources

Copyright ©2025 Educative, Inc. All rights reserved