Bharathi Batthula
3 min readJun 15, 2020

--

AWS ALB: Application Load Balancer 2nd part

Content-Based Routing

If your application is composed of several individual services, an Application Load Balancer can route a request to a service based on the content of the request. Two types of content routing are supported on the ALB they are host-based and path-based

Host-based Routing

You can create ALB rules to route a client request based on the domain name Host field of the HTTP header allowing you to route to multiple domains from the same load balancer.

HTTP request- Host field.

  • Specifies the domain name of the server and the TCP port number on which the server is listening.
  • Requests can be sent to a target group, which requests to content.dolfined.com are sent to the other.

AWS ALB- Path-based Routing

Using Path-based Routing you can route a client request based on the URL path of the HTTP header.

It routes incoming HTTP and HTTPS traffic based on the path element of the URL in the request.

This path-based routing allows you to route requests to, for /images to one target group and /videos to another target group.

Segmenting your traffic in this way gives you the ability to control the processing environment for each category of requests.

* Perhaps /images requests are best processed on a specific type of EC2 instances, while /videos requests are best handled by Graphics Optimized instances.

You can also create rules that combine host-based routing and path-based routing.

*This would allow you to route requests to images.example.com/thumbnails and images.example.com/production to distinct target groups.

Anything that does not match content routing rules can be sent to a default target group.

Load Balancing to ECS hosted Micro-Services

You can use a microservices architecture to structure your application as services that you can develop and deploy independently.

You can install one or more of these services on each EC2 instance, with each service accepting connections on a different port.

You can use a single Application Load Balancer to route requests to all the services for your application.

When you register an EC2 instance with a target group, you can register it multiple times,

  • For each service, register the instance using the port of the service

An ECS Service is:

A service that allows you to run and maintain a specified number of simultaneous instances of a task definition in an ECS cluster.

  • Underneath which we define the desired number of Tasks to be run

Service Load Balancing

Your Amazon ECS service can optionally be configured to use Elastic Load Balancing to distribute traffic evenly across the tasks in your service.

Application Load Balancers offer several features that make them particularly attractive for use with Amazon ECS service.

  • Application Load BHalancers allow containers to use dynamic host port mapping (so that multiple tasks from the same service are allowed per container instance).

AWS ALB

Application Load Balancers support path-based routing and priority rules.

The Application Load Balancer also integrates with EC2 Container Service (ECS) using Service Load Balancing.

  • Instances can be registered with multiple ports

* This allows for the request to be routed to multiple containers on a single container instance

  • Amazon ECS will automatically register tasks with the ALB using a dynamic container to host port mapping

*This allows for the dynamic mapping of services to ports specified in the ECS task definition.

  • The ECS task scheduler will automatically add these tasks to the ALB.

AWS ALB- ECS Service with multiple load balancer ports

Currently, an Amazon ECS service can only specify a single load balancer or target group.

If your task and container definition require multiple ports per container, then your service requires access to multiple load-balanced ports to serve the task containers.

To use ALB, and since each target group supports only one forwarding ports, you will need to separate the single HTTP/HTTPS service into two services.

  • One service will have a single container port task definition for HTTP port80.
  • The other will have a single container port task definition to handle HTTPS port 443.
  • Define two Target groups on the same ALB, one for HTTP port 80 and another for HTTPS port 443. Each service will leverage one of the target groups.

Thank you,

Bharathi.

--

--

Bharathi Batthula

Bharathi is a self driven and purpose-oriented person.The main mission is to create profound change in her career. contact her on bharathi.batthula6@gmail.com