Path-based Routing in AWS Application Load Balancer

Image for post
Image for post
www.datanextsolutions.com

Overview

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.

Example

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

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

Click on Create target group button

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 slides

Optionally set the Advance Health Check settings to the following

Adding EC2 Instances to Target Group

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.

Create an Application Load Balancer

Now the main thing, we need to create the Application Load Balancer. Click on the EC2 instances and then Elastic Load Balancer link

Click Create under Application Load Balancer

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

Select the Availability zones that your ALB would be running

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

Since we already created Target group select the existing target group en from the list

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

Add Forwarding Rules

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

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… column

Do the same for /en/ at the end you should have 2 rules defined as follows

Test

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.

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.

@IamZeeshanBaig

About DataNext

DataNext Solutions is a US based system integrator, specialized in Cloud, Big Data, DevOps technologies. As a registered AWS partner, our services comprise of any Cloud Migration, Cost optimization, Integration, Security and Managed Services. Click here and Book Free assessment call with our experts today or visit our website www.datanextsolutions.com for more info.

Written by

Cloud Security Expert & CEO of DataNext Solutions, helping people every day with the latest tech. Connect @LinkedIn http://bit.ly/zb-linkedin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store