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. You'll create a load balancer that receives public HTTP traffic and sends it to your EC2 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 in the Availability Zones that you plan to use for your load balancer. Ensure that the security groups for these instances allow HTTP access on port 80.

  • If your EC2 instances run in a VPC, be sure to launch them in public subnets. Note that by definition, the route table for a public subnet must have a route to the Internet gateway for the VPC.

  • 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.

Step 1: Define Your Load Balancer

First, provide some basic configuration information for your load balancer, such as a name, a network, and a listener.

A listener is a process that checks for connection requests. It is configured with a protocol and a port for front-end (client to load balancer) connections and a protocol, and protocol and a port for back-end (load balancer to back-end instance) connections. In this tutorial, you configure a listener that accepts HTTP requests on port 80 and sends them to the back-end instances on port 80 using HTTP.

To define 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 LOAD BALANCING, click Load Balancers.

  4. Click Create Load Balancer.

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

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

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

  7. [Default VPC] If you selected a default VPC and would like to choose the subnets for your load balancer, select Enable advanced VPC configuration.

  8. Leave the default listener configuration.

    Define your load balancer
  9. [EC2-VPC] Under Select Subnets, select at least one available subnet. The available subnets for the VPC for your load balancer are displayed under Available Subnets. Click the icon in the Action column for each subnet to attach. These subnets are moved under Selected Subnets.

    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 Select Subnets.

    You can select at most one subnet per Availability Zone. If you select a second subnet in an Availability Zone, it replaces the previously selected subnet for that Availability Zone. To improve the availability of your load balancer, select subnets from more than one Availability Zone.

    Select Subnets
  10. Click Next: Assign Security Groups.

Step 2: Assign Security Groups to Your Load Balancer in a VPC

If you selected a VPC as your network, you must assign your load balancer a security group that allows inbound traffic 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 can continue to the next step. By default, Elastic Load Balancing provides a security group for load balancers in EC2-Classic.

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.

    Select security groups
  3. Click Next: Configure Security Settings.

Step 3: Configure Security Settings (Optional)

For this tutorial, you can click Next: Configure Health Check to continue to the next step. For more information about creating a HTTPS load balancer and using additional security features, see HTTPS Load Balancers.

Step 4: 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, you customize the health checks for your load balancer.

To configure health checks for your instances

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

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

    2. Leave Ping Port set to its default value, 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.

      Configure Health Check
    4. Leave the other fields set to their default values.

  2. Click Next: Add EC2 Instances.

Step 5: Register EC2 Instances with Your Load Balancer

Your load balancer distributes traffic between the instances that are registered to it.

Note

When you register an instance with an elastic network interface (ENI) attached, the load balancer routes traffic to the primary IP address of the primary interface (eth0) of the instance.

To register EC2 instances with your load balancer

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

  2. Click Next: Add Tags.

Alternatively, you can register instances with your load balancer later on using the following options:

Step 6: Tag Your Load Balancer (Optional)

You can tag your load balancer, or continue to the next step. Note that you can tag your load balancer later on; for more information, see Tag Your Load Balancer.

To add tags to your load balancer

  1. On the Add Tags page, specify a key and a value for the tag.

  2. To add another tag, click Create Tag and specify a key and a value for the tag.

  3. After you are finished adding tags, click Review and Create.

Step 7: 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 EC2 instances.

To finish creating your load balancer

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

  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. (Optional) 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-load-balancer-1234567890.us-west-2.elb.amazonaws.com.) If your load balancer is working, you see the default page of your HTTP server.

Step 8: Delete Your Load Balancer (Optional)

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 a 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 LOAD BALANCING, click Load Balancers.

  3. Select the load balancer.

  4. Click Actions, and then 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 terminating your instances, see Stop and Start Your Instance or Terminate Your Instance in the Amazon EC2 User Guide for Linux Instances.