Elastic Load Balancing
Developer Guide (API Version 2012-06-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Getting Started with Elastic Load Balancing

This tutorial provides a hands-on introduction to using Elastic Load Balancing through the AWS Management Console, a point-and-click web-based interface. We'll create an external load balancer that receives public HTTP traffic and sends it to your instances.

Note that you can create your load balancer for use with EC2-Classic or a VPC. Some of the tasks described in this tutorial apply only to load balancers in a VPC.

Before You Begin

  • Complete the steps in Setting Up Elastic Load Balancing.

  • Launch the EC2 instances that you plan to register with your load balancer. Make sure that the security groups for these instances allow HTTP access on port 80.

  • If your EC2 instances run in a VPC, make sure to launch them in a public subnet.

  • Install a web server, such as Apache or Internet Information Services (IIS), on the EC2 instances that you plan to register with your load balancer.

Configure Listeners for Your Load Balancer

To configure listeners for your load balancer

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. From the navigation bar, select a region for your load balancers. Be sure to select the same region that you selected for your EC2 instances.

  3. In the navigation pane, under NETWORK & SECURITY, click Load Balancers.

  4. Click Create Load Balancer.

  5. On the Define Load Balancer page, do the following:

    1. In Load Balancer name, enter a name for your load balancer.

      The load balancer name you choose must be unique within your set of load balancers, must have a maximum of 32 characters, and must only contain alphanumeric characters or hyphens.

    2. From Create LB inside, select the same network that you selected for your instances: EC2-Classic or a specific VPC.

    3. [Default VPC] If you selected a default VPC and would like to select subnets other than the default subnets, select Enable advanced VPC configuration.

    4. Leave the other fields at their default values.

    Name your load balancer
  6. Click Continue to go to the next page in the wizard.

Configure Health Checks for Your EC2 Instances

Elastic Load Balancing automatically checks the health of the EC2 instances for your load balancer. If Elastic Load Balancing finds an unhealthy instance, it stops sending traffic to the instance and reroutes traffic to healthy instances. In this step, we customize the health checks for your load balancer.

To configure a health check for your instances

  1. On the Configure Health Check page, do the following:

    1. Leave Ping Protocol set to its default value of HTTP.

    2. Leave Ping Port set to its default value of 80.

    3. In the Ping Path field, replace the default value with a single forward slash ("/"). This tells Elastic Load Balancing to send health check queries to the default home page for your web server, such as index.html or default.html.

    4. Leave the other fields at their default values.

    Configure Health Check
  2. Click Continue to go to the next page in the wizard.

Select Subnets for Your Load Balancer in a VPC

To improve the availability of your load balancer, select at least two subnets in different Availability Zones.

Note

If you selected EC2-Classic as your network, or you have a default VPC but did not select Enable advanced VPC configuration, you do not see this page in the wizard and you can go to the next step.

To select subnets for your load balancer

  1. On the Select Subnets page, under Available Subnets, select the subnets. The subnets that you select are moved under Selected Subnets.

    Selected Subnets
  2. Click Continue to go to the next page in the wizard.

Assign a Security Group to Your Load Balancer in a VPC

If you created your load balancer in a VPC, you must assign it a security group that allows inbound to the ports that you specified for your load balancer and the health checks for your load balancer.

Note

If you selected EC2-Classic as your network, you do not see this page in the wizard and you can go to the next step. Elastic Load Balancing provides a security group that is assigned to your load balancer for EC2-Classic automatically.

To assign security group to your load balancer

  1. On the Assign Security Groups page, select Create a new security group.

  2. Enter a name and description for your security group, or leave the default name and description. This new security group contains a rule that allows traffic to the port that you configured your load balancer to use. If you specified a different port for the health checks, you must click Add Rule to add a rule that allows inbound traffic to that port as well.

    Select security groups
  3. Click Continue to go to the next page in the wizard.

Register EC2 Instances with Your Load Balancer

Your load balancer distributes traffic between the instances that are registered to it. You can register instances with your load balancer in two different ways:

To register instances with your load balancer manually, use the following procedure.

To register your EC2 instances with your load balancer manually

  1. On the Add EC2 Instances page, under Add Instances to Load Balancer, select the instances to register with your load balancer.

  2. Leave the other fields at their default values.

  3. Click Continue. You can optionally add tags to your load balancer. Otherwise, click Continue again to go to the Review page in the wizard.

Create and Verify Your Load Balancer

Before you create the load balancer, review the settings that you selected. After creating the load balancer, you can verify that it's sending traffic to your instances.

To finish creating your load balancer

  1. On the Review page, check your settings. If you need to make changes to the initial settings, click the corresponding edit link.

  2. Click Create to create your load balancer.

  3. After you are notified that your load balancer was created, click Close.

  4. Select your new load balancer.

  5. In the bottom pane, on the Description tab, check the Status row. If it indicates that some of your instances are not in service, its probably because they are still in the registration process. For more information, see Troubleshooting Elastic Load Balancing: Registering Instances.

  6. After you've verified that at least one of your EC2 instances is InService, you can test your load balancer. Copy the string from the DNS Name field and paste it into the address field of an Internet-connected web browser. (For example, my-lb-1234567890.us-west-2.elb.amazonaws.com.) If your load balancer is working, you see the default page of your HTTP server.

Delete Your Load Balancer

As soon as your load balancer becomes available, you are billed for each hour or partial hour that you keep it running. When you no longer need the load balancer, you can delete it. As soon as the load balancer is deleted, you stop incurring charges for it.

To delete your load balancer

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, under NETWORK & SECURITY, click Load Balancers.

  3. Select the load balancer.

  4. Click Actions and in the Actions drop-down box, click Delete.

  5. When prompted for confirmation, click Yes, Delete.

  6. (Optional) After you delete a load balancer, the EC2 instances associated with the load balancer continue to run, and you are billed for each hour or partial hour that you keep them running. For information about stopping or teminating your instances, see Stop and Start Your Instance or Terminate Your Instance in the Amazon EC2 User Guide for Linux Instances.