I’ve recently received some questions about the AWS Application Load Balancer, what advantages it provides, and how to monitor it. AWS is already calling the original Elastic Load Balancer it’s ‘Classic’ Load Balancer, so if you’re anxious to understand why so many are using it over the Classic ELB, this post is for you.
This post will describe the AWS Application Load Balancer, when to use it, and introduce how to connect it with your EC2 instances and autoscaling groups. Additional resources on integrating ECS Containers with the Application Load Balancer are also provided.
Operational Visibility From AWS
Machine data holds hidden secrets that deliver true insights about the operational health of your AWS infrastructure. Learn more about operational visibility from AWS today!
The AWS Application Load Balancer is the newest load balancer technology in the AWS product suite. Some of the benefits it provides are:
Path Based Routing
Select where to send requests based on the path of http request
This allows for multiple Target Groups behind a single Application Load Balancer, with EC2 and Container support
For example, you might route general requests to one target group of containers/EC2s, and route requests to render images to another microservice-specific (image rendering) target group
Your application needs to distribute TCP/IP requests – this is only supported with the Classic Load Balancer
If you’re looking for containerized application support, path based routing, better health checks, websocket support, or HTTP/2 support, the Application Load Balancer is the right choice for you.
How do I use it?
First, you’ll need to create your load balancer. A description of how to do this can be found in AWS’s documentation here. Make sure you make the following selections while setting up the load balancer:
Step 1:
Set ‘Scheme’ to ‘Internet Facing’ and make sure there is a Listener on port 80 (HTTP)
Select the Default VPC, or if launching the ALB into another VPC, select one where you have testing servers running or are able to launch servers for testing
Step 3: Create or use an existing security group that allows inbound HTTP traffic of port 80
Step 4: Create a new Target Group and select port 80/protocol HTTP
Step 5: Skip for now and create the load balancer
Distribute Traffic to Existing EC2 Instances
Check ALB Configuration
Before you begin, verify that your ALB has a Listener set to port 80 – we will test with HTTP requests although when using your load balancer in production make to only allow interactions via HTTPS port 443
To verify, go to the EC2 Dashboard > Load Balancers > Select your ALB > Select the ‘Listeners’ tab
Next, double check that the Application Load Balancer’s security group allows inbound HTTP and HTTPS inbound traffic
To check this, go to the EC2 Dashboard > Load Balancers > Select your ALB > Under ‘Description’ click on ‘Security group’ > Make sure the correct security group is selected and choose the ‘Inbound Rules’ tab
Send AWS Application Load Balancer Traffic to an EC2 Instance
If you have an existing test server located in the same VPC as your ALB, follow these steps:
First, navigate to the EC2 Dashboard > Load Balancers > Select your ALB > Select ‘Targets’ tab > Select ‘Edit’
Select the test server(s) you want to distribute traffic to and click ‘Add to Registered’, then click ‘Save’
If you want to create a test server to connect to the ALB, follow these steps:
Launch a Linux AMI (see documentation here for more info). While launching, you must ensure that:
Step 3: You have selected the same VPC as the VPC your ALB was launched into
Step 3: You have a running web server technology and a sample web page – under ‘Advanced Details’ you can use the following bootstrap script if you are not familiar with this:
#!/bin/bash
yum install httpd -y
service httpd start
mkdir /var/www/html/test
echo 'Your Application Load Balancer test page!' > /var/www/html/test/index.html
Step 6: Allow inbound HTTP traffic from your ALB’s security group
Now that you have a running web server to test with, navigate to the EC2 Dashboard > Load Balancers > Select your ALB > Select ‘Targets’ tab > Select ‘Edit’
Select the test server(s) you want to distribute traffic to and click ‘Add to Registered’, then click ‘Save’
Finally, test your load balancer by navigating to its DNS name in a web browser. You can find it by selecting your ALB and viewing the ‘Description’ tab. Use the pattern <DNS_Name>/test/index.html to see our test page:
Distribute Traffic to EC2s in AutoScaling Groups
If you do not already have a launch configuration, create one following the same steps described above for launching a test Linux AMI server. To configure an Auto Scaling Group to auto-register instances to the ALB, see the documentation here.
The most important step in the ‘Create Auto Scaling Group’ process is under ‘Advanced Details’. Make sure to check the ‘Receive traffic from one or more load balancers’ box and add your ALB:
Distribute Traffic to Your Containers
A Cloud Guru’s Application Load Balancer course – Get a complete walk through of how AWS ECS integrates with the ALB, Michael Wittig and Andreas Wittig offers an excellent tutorial.