Load Balancers are network devices that you can use to distribute traffic across multiple servers. AWS Elastic Load Balancers is a managed service that provides load balancing for your EC2 instances and enables the use of automatic scaling.
What is a load balancer?
Instead of having a large web server that handles all the work of operating your application, Load Balancers allows you instead to have two or three smaller servers that each handle part of the work. Load Balancer sits in front of these servers and directs even incoming traffic to them.
Under the hood, a Load Balancer is just another server running a modified version of HAProxy. You can set this up yourself if you want, but as with many other AWS services, it̵7;s great that everything works for you. They are easy to install and you do not have to worry about them once they are up and running.
AWS Elastic Load Balancers supports HTTP / HTTPS traffic at the request level and TCP and UDP at the connection level. They cost $ 17 per month plus additional data costs.
Load Balancers enables high availability – two servers are in themselves much better than one server, because if a server crashes or has to be restarted, it does not take your application offline. On AWS, they are also used for automatic scaling, a feature that can automatically start additional servers when CPU usage becomes too high. This allows your application to scale throughout the day and as needed. Load Balancers is used in this case to direct the traffic evenly to each instance in the Auto-Scaling group.
From the EC2 Management Console, select “Load Balancers” in the sidebar and create a new Load Balancer:
To balance HTTP / HTTPS traffic, select Application Load Balancer. For everything else, select Network Load Balancer.
Give it a name and make sure it is set to “internet flip”, unless you are balancing internal traffic. By default, only HTTP is enabled, so add an HTTPS listener:
You must select at least two subnets in different accessibility zones for the load balance to be displayed. If you are unsure, just select the subnet that your servers are currently in, which you will find under the “Instances” tab in the EC2 console, and select another if you are only using one subnet.
On the next screen, you need to set up HTTPS. This is done using the AWS Certificate Manager, which provides SSL certificates for encrypting the load balancer’s traffic. If you already have a certificate in ACM, you can select it here, but if not, click “Request a new certificate from ACM” to set up a new one.
You will be taken to a new page where you must enter the domain names you plan to use with this load balance. If you want to use subdomains, you can enter them manually or just enter a secondary wildcard, as follows:
You must verify that you own these domains before the certificate can be issued. Open your DNS configuration and add a new CNAME record with the name and value given to you by ACM. If you use Route 53 as your DNS provider, you can just click the button to create these automatically.
It may take a while to process, up to an hour, but when done, turn “Pending Validation” to a green “Validated” and you can update and select the certificate in the load balancing setting.
On the next screen, simply select the security group currently used by your instances, unless you want to create a new one and configure it manually.
Then you need to create a new “target group” for Load Balancer to point to. You add your instances to this group and it balances between them. Make sure “Instance” is set as the type, unless you want to give it a list of IP addresses.
On the next screen, select the instances you want to use with this load balance.
When done, proceed to the review and click “Create” to launch your load balancer.