How to create Application Load Balancer for EC2 instances
How to create Application Load Balancer for EC2 instances

Create an Application Load Balancer for EC2 instances to improve traffic distribution efficiency, enhance fault tolerance, and optimize application.

Table of Contents

Application Load Balancer (ALBs) are critical in managing the traffic to your web applications deployed on AWS. By efficiently distributing incoming application traffic across multiple targets, such as Amazon EC2 instances. ALBs enhance your applications availability and fault tolerance.

Benefits of Using an Application Load Balancer with EC2 Instances

1. Improved Fault Tolerance: By continuously checking the health of linked EC2 instances. ALBs can redirect traffic away from failed instances. Thus minimizing downtime and ensuring a seamless user experience.

2. Scalability: ALBs automatically adjust to changes in incoming application traffic. Therefore making it easier for applications to scale up or down without manual intervention.

3. Enhanced Security: Application Load Balancers offer robust security features such as built-in SSL/TLS decryption. Which enables them to serve as the first line of defense against cyber threats.

4. Operational Efficiency: You can also the management of user sessions by enabling sticky sessions.

5. Advanced Routing Capabilities: Furthermore, ALBs support content-based routing. Thus allowing you to route traffic based on the content of the request, including URLs, headers, and HTTP methods.

Prerequisites for Creating an Application Load Balancer

Before you begin the process of creating an Application Load Balancer for your EC2 instances. It’s important to ensure that you have the following prerequisites in place:

1. AWS Account Setup: You must have an active AWS account. If you do not have one. You can sign up at the AWS website.

2. Existing EC2 Instances: Ensure that you have two or more EC2 instances running. These instances will be the targets for your load balancer.

3. Required IAM Permissions: Also, ensure that your AWS user account has the necessary permissions to create and manage load balancers.

Step-by-Step Guide to Creating an Application Load Balancer

Once you have the prerequisites in place. You can follow these steps to create an Application Load Balancer for your EC2 instances:

Step 1: Access the EC2 Management Console

Sign in to your AWS Console and navigate to the EC2 dashboard. This is your central hub for all operations related to EC2.

Step 2: Navigate to the Load Balancers Section

Then within the EC2 dashboard, find the “Load Balancers” section under the “Load Balancing” menu. From there click on “Create load balancer”.

Application Load Balancer Dashboard

From there select application load balancer.

Load balancer type

Step 3: Configure the Load Balancer

Here give the Load balancer name. And also set the following options.

Creating a Application Load Balancer

Select at least two availability zones from there.

Creating a Application Load Balancer: Network Mapping

Then, select the security group that has the necessary ports allowed. 

Creating a Application Load Balancer: Security Group

Now click a target group by clicking on the “Create target group” (open it in a new tab) link.

Creating a Application Load Balancer: Network Rule

Here select the “Target type” to instances.

Creating a Application Load Balancer: Target group

And also use a Target Group name.

Creating a Application Load Balancer: Specifying Target group name and port

Keep everything else default and then click on next.

After that, select the EC2 instances that you want to connect with the load balancer. Then click on “Include as pending below”.

Creating a Application Load Balancer: Adding instances to target group

Now click on “Create target group”.

Creating a Application Load Balancer: Finalizing targets for target group

Finally, get back to the ALB configuration, refresh the target group, and select the newly created target group.

Creating a Application Load Balancer: Selecting target group

Everything looks good, you can include WAF and Global Accelerator. As this is a simple demo. I will be skipping this.

Skipping AWS WAF and AWS Global Accelerator

Now, proceed to do a final review, and then click on ‘Create load balancer’.

Verifying the Load Balancer

The load balancer will take some time to get ready. It will change the status from “Provisioning” to “Active”.

Successful Creation of AWS Application Load Balancer

Once the status is shown “Active”, copy the “DNS name”.

ALB Status is now Active

Navigate to the browser and paste the URL. Then, try refreshing the URL. As you do so, you will see it’s changing the instances each time you refresh.

Confirming Load Balancer Between 2 instance
Confirming Load Balancer Between 2 instance

You can now use your domain in Route 53 and create an alias for this ALB. As a result, your users will not notice they are switching servers. But you must make sure that your application is capable of utilizing a Load Balancer.

Cleaning Up

Once you are done practicing, you should remove all the resources to avoid any charges.

Navigate to the “Load Balancer” Dashboard, and then select the load balancer. Then from “Actions” select “Delete load balancer”.

Deleting Load Balancer

Follow up with the confirmation. After that, navigate to the Target Group, and select the target group. From there click on “Actions” and delete. 

Deleting Target Group

Next, you can either delete the EC2 instances that you created or stop them.

Elite Cloud is an officially authorized AWS cloud agent , focusing on helping enterprises introduce AWS services, reduce cloud costs, optimize accounting management and provide technical support.

👉 Book a session with the Elite Cloud team today

AWS AWS ALB AWS EC2