|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
Elastic Load Balancing automatically distributes and balances the incoming application traffic among all the instances you are running, improving the availability and scalability of your application. The service also makes it easy to add new instances or remove underused 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. 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 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.
To create a load balancer
Define a load balancer:
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the top navigation bar, click US East (N. Virginia) in the region selector.
In the left navigation pane, click Load Balancers.
Click Create Load Balancer.
In the Create a New Load Balancer wizard, on the Define Load Balancer page, enter a name
for your load balancer. In this example, type
Leave the Listener Configuration set to the default value for this example. The Load Balancer Port and Protocol specifies the port and protocol that the load balancer will use to listen for traffic from clients. The Instance Protocol and Port specifies 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.
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.
Configure the health check:
Elastic Load Balancing routinely checks the health of each load-balanced Amazon EC2 instance. If Elastic Load Balancing finds an unhealthy instance, it stops sending traffic to the instance and reroutes traffic to healthy instances.
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 information on using HTTPS with Elastic Load Balancing, see Elastic Load Balancing Developer Guide 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.
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
default.html, or a different
name. When you deploy your application, consider creating a special
lightweight 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.
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.
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.
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 change its port configuration, create a replacement load balancer.
On the Confirmation page, click Close.
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.
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.
Add an Availability Zone:
In the list of load balancers, 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.
Here's where you are in building your architecture.
In Step 4: 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 Step 8: Update Your Amazon EC2 Security Group.