(upbeat music)
- Hello, I'm Gnaneshwari, a cloud support engineer
here at the AWS office in Bangalore, India.
Today, I'm gonna show you
how you can achieve path-based routing
on an Application Load Balancer.
In an Application Load Balancer, you can have a listener
with one or more routes that forward requests
to specific target groups based on the URL path.
In this video, we will consider an example
where we have two separate services
to run for URL/path1 and /path2 on port 80.
I'll walk you through creating target groups,
registering targets, and creating routes
on the load balancer.
Let's get started.
Prerequisites.
Launch Amazon EC2 instances
and deploy the microservices on them.
I have launched the instances Service A and Service B
that run a microservice for /path1/*
and Service C and Service D
that run a microservice for /path2/*.
Now, let's go ahead and create two target groups
for the microservices for /path1 and /path2 respectively.
After logging into the AWS management console,
navigate to the Amazon EC2 console.
On the navigation bar, select the same region
that you selected for the EC2 instances.
On the navigation pane, under Load Balancing,
choose Target Groups.
Create a target group for the first set of targets.
Choose create target group.
Specify a name, such as TargetGroup1.
And then the protocol, port,
and the VPC for the target group.
Choose Create.
To register targets, select the new target group.
On the Targets tab, choose Edit.
For instances, select instances,
service one and service two,
that run the microservice for /path1.
Specify a port for the instances,
choose add to registered, and then choose Save.
In the same way, create another target group, TargetGroup2,
and register instances that run the microservice for /path2.
On Application Load Balancers' Listeners tab,
for the listener you need the path-based routing on.
Choose view/edit rules.
And then choose the add rules icon.
For /path1, let's specify the rule as follows.
Choose Insert Rule.
Choose add condition, path is, and enter /path1.
To save the condition, choose the check mark icon.
Choose add action, forward to,
and then choose the TargetGroup1 that we just created.
To save the action, choose the check mark icon.
To save the rule, choose Save.
In the same way, let's create a rule for /path2 as well.
Choose Insert Rule.
Choose add condition, path is, and enter /path2.
To save the action, choose the check mark icon.
Choose add action, forward to,
and then choose the TargetGroup2 that we just created.
To save the action, choose the check mark icon.
To save the rule, choose Save.
You can have similar rules for other listeners,
defined on your load balancer as well.
Thanks for watching, and happy cloud computing
from all of us here at AWS.
(upbeat music)