Getting Started with Application Load Balancer

An Application Load Balancer is a load balancing option for the Elastic Load Balancing service that operates at the application layer and allows you to define routing rules based on content across multiple services or containers running on one or more Amazon Elastic Compute Cloud (Amazon EC2) instances.
Follow the below simple steps for setting up an application load balancer. This blog post also shows how you can switch from a classic load balancer to an application load balancer.

Applications

We have two servers already setup with wordpress and drupal applications, respectively.

  • Wordpress Application on one server alt

  • Drupal Application on another server alt

Target Groups

Create Target Groups for each of the application.

  • Drupal Target Group:

Click on create target group.

alt

Give name to the group. Select VPC and Configure the health checks.

alt

  • Wordpress Target Group:

Similarly, create a target group for the wordpress application. Give a name. Select vpc and configure health checks.

alt

Now, we have two targets groups for drupal and wordpress applications, respectively.

alt

Register targets for each of the group.

  • Drupal

Go to Targets tab. Click Edit.

alt

Select the instance with drupal application running on it. Click Add to registered.

alt

The instance will show under the Registered Instances.

alt

  • Wordpress:

Similarly, for the wordpress target group, register the instance with wordpress aplication running on it.
Go to Targets tab. Click Edit.

alt

Select the wordpress server. Click Add to registered.

alt

Save. The instance will get added to the Registered Instances.

alt

Application Load Balancer

Create Load Balancer.

alt

Select Application Load Balancer.

alt

Configure the load balacer. Give a name. Choose subnets in each zone.

alt

alt

Select an existing one or create a new security group for the load balancer.

alt

Configure Routing. Create new or select an already existing target groups for the default route.

alt

alt

We have selected drupal target group.

alt

Since we have already registered the instance to the target group, the instance will automatically appear in Register Targets in the next screen.

alt

Click Next and Reviews the configurations.

alt

Create.
The Application Load Balancer will get started to provision.

alt

The State will get changed from provisioning to active once it becomes available.

alt

Now, add a rule to the listener so that whenever a path pattern for a rule is matched, ALB will route the traffic to the corresponding target group.
Go to Listeners tab, Click Add rule.

alt

Specify path pattern and select the target group.

alt

Similarly, create a rule set for wordpress.

alt

Now, Hit the ALB’s DNS name with the path pattern /drupal. The Application will load.

alt

Also, hit the ALB’s DNS name with path pattern /wordpress. The Application will load.

alt

Enable SSL

Let's enable SSL to our applications. Here, we are using ACM for the SSL certificates.
Add Listener.

alt

Add rule.

alt

Specify path patterns for both the applications.

alt

Switching Classic Load Balancer

If you want to migrate the classic load balancer to application load balancer, refer this link: https://github.com/aws/elastic-load-balancing-tools.
So, we have one classic load balancer as shown below:

alt

The elastic-load-balancing-tool will copy the configuration of this classic load balancer to create a new application load balancer with same configurations. The command to create the application load balancer is:

python copy_classic_load_balancer.py --name classic-load-balancer-name --region region-name  

alt

So a new application load balancer will be ready with same configurations as of classic load balancer.

alt alt

To register instances, use the command:

copy_classic_load_balancer.py --name my-load-balancer -–region region-name --register-targets  

and That's it..!! Happy Load Balancing across Applications..!! :)

Priyanka Sharma

Priyanka is Senior Cloud and DevOps Engineer. She can churn out CloudFormation templates at a moment's notice and play with Chef/Ansible. Dancing, music, badminton and word games are her hobbies

comments powered by Disqus