What is Application Load Balancer?
The Application Load Balancer works at the layer 7 (application layer), and the standard load balancer works at the layer 4 (transport layer).
There are many benefits with it. It enables more sophisticated load balancing, like multiple port to certain paths. But for me, the most biggest benefit is I can use HTTP/2 with it.
The AWS official document explains more in detail.
- AWS Elastic Beanstalk
I’ve been using the classic load balancer, and change to new Application Load Balancer.
Elastic Beanstalk with Application Load Balancer
This is how I create new environment and make it use new Application Load Balancer and HTTP/2. The quick setup.
1. Create new environment
$ eb create Enter Environment Name (default is my-app): test-env Enter DNS CNAME prefix (default is my-app): test-env-DLW24ED23SF Select a load balancer type 1) classic 2) application (default is 1): 2
The new instance and ALB was created by this. Don’t forget to choose No. 2 at the selecting a load balancer type.
2. Add config file to .ebextensions
Declare that your app is going to use the Application Load balancer.
# .ebextensions/application-load-balancer.config option_settings: aws:elasticbeanstalk:environment: LoadBalancerType: application
3. Console Setup
Go to AWS console and set up.
Set security group to allow HTTPS.
Attach SSL certificate to your new load balancer.
4. Done! (No settings needed to your NginX)
You don’t have to add any additional config to your NginX. I’m surprised with this, but the Application Load Balancer handle the HTTP2 so that you don’t have to do with your NginX.
There’s a nice Chrome extension to check whether the website supports HTTP/2 or not.
Just download it and you can see the result.
Health Check Problem
I set up the health check URL to “/admin” at the Elastic Beanstalk configuration, but the health check request does not change and the request keep coming to the top page “/”.
This causes the application’s health to be ‘Severe’ because my app redirects the request that come to the top page. So it returns 302, not 200.
Finally I found the reason. This is because it is needed to set up the health check URL for the Application Load Balancer too. You can set this at
EC2 > Load Balancing > Target Groups > Health Checks . After added the right setting, everything is fine.
This Application Load Balancer is still just a new fucntion, so that it is not easy to understand how to setup, but it has very good feature that we can use HTTP/2. You don’t have to modify / tune your code to get the better performance, so I strongly recommend to set up this.