# Application Load balancer

**AWS** offers 3 types of load balancers as part of **Elastic Load Balancer (ELB)** service one is called **Classic Load Balancer**, **TCP load balancer** and the latest is the **Application load balancer (ALB)**.

ALB offers some unique features over Classic ELB and one of the features is **Path-based Routing**. What is Path-based Routing? well in simple terms the ALB could forward the incoming requests to different destinations based on the path as shown in the slide.Path-based routing example

![](https://miro.medium.com/max/1400/1*JKv06SJiCDJqExr7dUBCyA.jpeg)

## Example <a href="#c674" id="c674"></a>

In the above slide, if the request contains the text **/en/** the request would be forwarded to EC2 instance where our app (Hello World) is running in English and if the request contains the text **/es/**, then the request would be redirected to other EC2 instance and we will see the Hello World message in Spanish.

**Note**: In this post Setup of EC2 is not covered.

## Creating a Target Group <a href="#e5ec" id="e5ec"></a>

The first step is to set up the target groups, you need at least 2 target group to configure Path-based routing.

To start things click on the **Target Groups** under **EC2** Instances We have 2 EC2 Instances running, click Target Groups link to start

![](https://miro.medium.com/max/1400/1*Bzqw3qb7Md8nmifPVCuWQw.png)

Click on **Create target group** buttonCreate a Target Group

![](https://miro.medium.com/max/1400/1*RuanfH0tnB0I8bxRAN8Z2Q.png)

In my example, I have set up 2 target groups one is called **‘en’** which routes to **/en/** and other is **‘es’** which routes to **/es/** as shown in the following slidesTarget group settings

![](https://miro.medium.com/max/1400/1*rTf3ZG-t0s17-XC6taGtwA.png)

Optionally set the **Advance Health Check settings** to the followingHealth check settings

![](https://miro.medium.com/max/1400/1*PCDP4Pve_fAJM2nrgXiKsA.png)

## Adding EC2 Instances to Target Group <a href="#fe09" id="fe09"></a>

Next step is to add **EC2** instances to the **target groups**. Select the target group switch to the **Targets** tab and click the **Edit** button.Adding Targets EC2 Instances to the groupsAssign your instances to the group

![](https://miro.medium.com/max/1400/1*9uhdyt8Ngp_jT7v5h1LA9w.png)

![](https://miro.medium.com/max/1400/1*y5LZdC33Vnu5L5AGToLDnQ.png)

## Create an Application Load Balancer <a href="#b0df" id="b0df"></a>

Now the main thing, we need to create the **Application Load Balancer.**&#x43;lick on the **EC2** instances and then **Elastic Load Balancer** link

Click **Create** under **Application Load Balancer**Create ALB

![](https://miro.medium.com/max/1400/1*_oazqkTbumLmSScTLSgcsA.png)

**Name** your load balancer and add **ports** that your ALB would be listening on ALB name and Ports

![](https://miro.medium.com/max/1400/1*S6_csamjgv4WfJCgprre6g.png)

**Select** the **Availability zones** that your ALB would be running ALB AZs

![](https://miro.medium.com/max/1400/1*TjvYrOsnsbuelM_s0hlgVg.png)

Select **Security Group** for ALB, make sure you allow ports that ALB is listening and forwarding onSecurity WarningSelect Security Group

![](https://miro.medium.com/max/1400/1*v4QJaCxnYMVxhY2-ARSIJA.png)

![](https://miro.medium.com/max/1400/1*veClI847grhCXc426jXaXQ.png)

Since we already created **Target group** select the **existing** target group **en**from the listSelect or Create Target GroupReview Target Instances Review ALB settings and click Create

![](https://miro.medium.com/max/1400/1*ao68v_jp1-RZ0UknVGv63g.png)

![](https://miro.medium.com/max/1400/1*eFjFgCVb6V9ZojoYj0oJIQ.png)

![](https://miro.medium.com/max/1400/1*6kZhtOSFX0rDMv8vnf7CKA.png)

Once created wait for few minutes to change the ALB **status** to **Active** ALB status

![](https://miro.medium.com/max/1400/1*wWpg-375L4ElN0WWE5xN2w.png)

## Add Forwarding Rules <a href="#id-3089" id="id-3089"></a>

Now we have created our target groups and ALB. Now it’s time to add the Path based rules to our Application Load Balancer.

**Click** the **ALB name**, then select the **Listeners** tab and under Listener click **View/edit rules**Create or Edit ALB rules

![](https://miro.medium.com/max/1400/1*rEuYnC3zrkwp2CsRRuuE4Q.png)

Click the **+ sign** on top and click **Insert Rule** then select the **Rule type** as **Path**, enter **/es/** in the **is** and select a target group **es** in the **Forward to…**&#x63;olumnCreating Rules

![](https://miro.medium.com/max/1400/1*kUWzaVOPMr9VhySKEZiLNw.png)

Do the same for **/en/** at the end you should have 2 rules defined as followsPath-based rules

![](https://miro.medium.com/max/1400/1*9yXIXL3zLWv1c-6MhR1XEw.png)

## Test <a href="#id-1b99" id="id-1b99"></a>

Once we have these rules created, copy the DNS name of the ALB and enter in the browser with **/en/** and **/es/** in the URL you should see the different sites accordingly.Test Results

![](https://miro.medium.com/max/996/1*mV39Icqriklg7sEqrK8tOg.png)

![](https://miro.medium.com/max/1004/1*yjJz8MkwojcCK4C0FuPVhA.png)

P.S. Spanish translation is courtesy of Google Translate.

Hopefully, this post helps you to understand how to add Path-based routing to AWS Application Load Balancer. **Feel free to comment for any questions I would be happy to help.**
