Creating an Elastic Load Balancer in AWS
Recommended by 0 users
Create an Elastic Load Balancer (ELB)
Elastic Load Balancing automatically distributes and balances the incoming application traffic among all the instances you are running, thus improving the availability and scalability of your application. It seamlessly provides load balancing capacity. You create a load balancer and register instances with it which serves as a single point of contact for clients. Addition and deletion of EC2 instances from the load balancer can be done without disturbing the flow of information.
If the call completes successfully, a new load balancer is created with a unique Domain Name Service (DNS) name. The load balancer receives incoming traffic and routes it to the registered instances. You can create up to 20 load balancers per region per account. You can request an increase for the number of load balancers for your account.
The service also makes it easy to add new instances or remove under-used instances when you need to increase or decrease the capacity of your application. The following diagram shows how the load balancer works. In this diagram, the load balancer contains two listeners. By default, the load balancer is configured to listen HTTP traffic on port 80. The first listener accepts traffic on port 80 using HTTP and forwards these requests to the Amazon EC2 instances using HTTP on port 8080. The other listener accepts traffic on the port 443 using HTTPS and forwards these requests to the Amazon EC2 instances using HTTPS on port 4443.
You can specify the protocol and port for both the client and the Amazon EC2 instances. In this step, we will create a load balancer for an HTTP service. We’ll specify that the load balancer listen on port 80 for incoming traffic from clients and then distribute traffic on port 80 to the instances.
As soon as your load balancer becomes available, you’re billed for each hour or partial hour that you keep the load balancer running. For more information about Elastic Load Balancing pricing, see the Elastic Load Balancing details page. For more information about elastic load balancers, go to the Elastic Load Balancing Documentation.
Creating a load balancer
You can create an internal load balancer to distribute traffic to your EC2 instances in private subnets.
Load Balancer has two components: the load balancer and the controller service. The load balancer monitors traffic, whereas the controller service monitors load balancers.
If a call is finished, a new load balancer is created with a unique Domain Name Service (DNS). Almost 20 load balancer can be created per account which is also extendable.
1. Define a load balancer:
- Open the Amazon EC2 console at https:// console.aws.amazon.com/ ec2/.
- In the Navigation pane, in the Region list, click US East (Virginia).
- In the Navigation pane, click Load balancers.
- In the Create a new load balancer wizard, in the load balancers pane, click create load balancers.
- On the define load balancer page, enter a name for your load balancer. In this example, type MyLB.
- Leave the Listener Configuration set to the default value for this example. The Load Balancer Port and Protocol specify the port and protocol that the load balancer will use to listen for traffic from the clients. The Instance Protocol and Port specify the port and protocol the load balancer will use to route traffic to the instances. For example, if you want the load balancer to forward traffic to the instances using port 8080, you can specify that here.
Note: After you configure the listener information, you cannot change it. If you want to update this information, you will need to create a new load balancer.
- Click Continue.
2. Configure the health check:
Elastic Load Balancing routinely checks the health of each load-balanced Amazon EC2 instance. This health check determines the instances of health status. If Elastic Load Balancing finds an unhealthy instance, it stops sending traffic to the instance and reroutes traffic to healthy instances.
a) On the Configure Health Check page of the Create a New Load Balancer wizard, do the following:
On the Configure Health Check page, under Configuration Options, do the following:
- Leave Ping Protocol set to its default value of HTTP. In the future, if you want to use a more secure protocol for the load balancer to send ping requests to your instances, you can use HTTPS and specify a different port. For more information regarding HTTPS with Elastic Load Balancing, see Elastic Load Balancing Security Features in Elastic Load Balancing Developer Guide.
- Leave Ping, Port set to its default value of 80. Elastic Load Balancing uses the ping port to send health check queries to your Amazon EC2 instances.
Note: If you specify a ping port value, your Amazon EC2 instances must accept incoming traffic on the port that you specify. You can set a port value other than 80, and you can change this value at any time.
- In the Ping Path box, replace the default value with a single forward slash (“/”).
Elastic Load Balancing sends health check queries to the ping path you specify. This example uses a single forward slash so that Elastic Load Balancing sends the query to your HTTP server’s default home page, whether that default page is named index.html, default.html, or any other different name. When you deploy your application, consider creating a special light-weight file that responds only to the health check. Doing so helps differentiate between traffic that is hitting your site and responses to the load balancer.
b) On the Configure Health Check page, under Advanced Options, set the Healthy Threshold to 2. Accept the default values on the other options.
Typically, the default value of 10 is fine for a healthy threshold. To expedite this tutorial, we specify 2, so you don’t have to wait as long to see healthy instances.
c) Click Continue.
3. Add Amazon EC2 instances:
- On the Add EC2 Instances page, click Continue.
- Review your settings. To make changes to the settings, click the edit link for a specific step in the process.
Note: After you create a load balancer, you can modify any of the settings except for Load Balancer Name and Port Configuration. To rename a load balancer or to change its port configuration, create a replacement load balancer.
- Click Create.
- On the Confirmation page, click Close.
The confirmation window closes, returning you to the Load Balancers page. Your new load balancer now appears in the list.
As a best practice, you should have sufficient instances across Availability Zones to survive the loss of any one Availability Zone. Therefore, we will ensure that our load balancer points to multiple Availability Zones in the next step.
4. Record the public DNS address:
- In the Load Balancers pane, click MyLB.
- Click the Description tab.
- Write down the public DNS address. You will need it later in this tutorial.
5. Add an Availability Zone:
- In the Load Balancers pane, click MyLB.
- Click the Instances tab.
- Click the plus icon.
- In the Add and Remove Availability Zones dialog box do the following:
Click us-east-1b: 0 instances.
Click us-east-1c: 0 instances.
In a later task, you will launch instances in these two Availability Zones by using Auto Scaling. You’ll see that the Availability Zones column for the load balancer is updated for both Availability Zones.
Advantages of using Load Balancing:
Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances in the cloud. It enables you to achieve greater levels of fault tolerance in your applications, seamlessly providing the required amount of load balancing capacity needed to distribute application traffic. Its most important benefits are availabile, secure and elastic.
- Distribution of requests to EC2 instances in multiple availability zone
- Hazard of overloading of instances is minimised
- Continuous monitoring of health instances
- Support for the sticky session feature
- Support for end-to-end traffic encryption.
When You’re At
Here’s where you are while building your architecture.
In the process of Launch an Instance, you set a security group to allow all traffic to connect to your Amazon EC2 instance via port 80 (HTTP). Now that you have created an Elastic Load Balancer, you can update your security group to allow only incoming HTTP traffic from your Elastic Load Balancer. Move on to further post Update Your Amazon EC2 Security Group.