Elastic Load Balancing
Developer Guide (API Version 2011-11-15)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Creating a Basic Load Balancer in Amazon VPC

This topic uses an example to walk you through the process for creating a basic HTTP load balancer on Amazon VPC and registering your EC2 instances with the newly created VPC load balancer. This example uses default configurations for security group, listener protocols and ports, and for the health check.

The following task list gives you a general overview of the steps you'll need to follow to create a basic load balancer in Amazon VPC. After this task list you'll step through detailed procedures for each part of the creation process.

Creating a Basic Load Balancer in Amazon VPC

1

Configure the listeners for your load balancer by specifying the ports and protocols to use for front-end connection (client to load balancer) and back-end connection (load balancer to back-end instance).

2

Configure a health check for your Amazon EC2 back-end instances.

3

Select the subnets to launch your load balancer.

4

Select security groups to assign to your load balancer.

5

Add instances to your load balancer.

6

Review settings.

7

Create and test your load balancer.


You can choose to create your load balancer within Amazon VPC using the AWS Management Console, the command line interfaces, or Query API.

Using the AWS Management Console

To create a basic load balancer in your Amazon VPC

  1. Start the Create Load Balancer wizard:

    1. In the Amazon EC2 Console Dashboard page, click Load Balancers in the Navigation pane.

      EC2 Console

    2. On the Load Balancers page, click Create Load Balancer.

  2. On the DEFINE LOAD BALANCER page, enter a name for your Amazon VPC load balancer (e.g., MyVPCLoadBalancer).

  3. Click the arrow in the Create LB inside box and select the virtual private cloud in which you want to create your load balancer.

  4. Leave the Listener Configuration set to the default value.

    Name your load balancer

  5. Click Continue to configure the health check for your instances.

  6. Configure the health check settings that your application requires.

    Configure Health Check

  7. Click Continue to select the subnet in which you want to launch your load balancer instance.

  8. In the Available Subnets table, click the green button at the left to select the subnet in which you want to have your load balanced instances.

    Select Subnets

    Your selected subnets are displayed in the Selected Subnets table.

    Selected Subnets

  9. Click Continue to select security groups to assign to your load balancer.

  10. If you use a pre-existing security group, ensure that it allows ingress to the ports that you configured the load balancer to use. If you create a security group in this step, the console will define these ports to be open for you. This example uses the default security group associated with your virtual private cloud.

    Select Choose one or more of your existing Security Groups and then select the default security group.

    Select security groups

  11. Click Continue to add running EC2 instances to your load balancer.

  12. In the Manually Add Instances to LoadBalancer table, check the boxes in the Select column to add instances to your load balancer.

    Add Amazon EC2 Instances

    [Note]Note

    When you register a multi-homed instance (an instance that has an Elastic Network Interface attached) with your load balancer, the load balancer will route traffic to the primary IP address of the instance (eth0). For more information on using Elastic Network Interfaces, go to Elastic Network Interfaces.

  13. Click Continue to review your configuration. On the REVIEW page, click Create to create your load balancer.

Using the Query API

This example walks you through the process for creating a basic HTTP load balancer on Amazon VPC and registers Amazon EC2 instances with the newly created VPC load balancer. This example uses a default security group.

To create a basic load balancer in your Amazon VPC

  1. Call CreateLoadBalancer using the following parameters:

    • Subnets = subnet-450f512c

    • Listener

      • Protocol = HTTP

      • InstanceProtocol = HTTP

      • InstancePort = 8080

      • LoadBalancerPort = 80

    • LoadBalancerName = MyVPCLoadBalancer

    • SecurityGroups = sg-b9ffedd5

  2. The operation returns the DNS name of your load balancer. You can then map any other domain name (such as www.example.com) to your load balancer’s DNS name using CNAME or some other technique.

To register your Amazon EC2 instances with your VPC load balancer

You should only register instances that are in the Pending or Running state and are in a Virtual Private Cloud (VPC).

  • Call RegisterInstancesWithLoadBalancer with the following parameters:

    • LoadBalancerName = MyVPCLoadBalancer

    • Instances = [ i-4f8cf126, i-0bb7ca62 ]

[Note]Note

When you register a multi-homed instance (an instance that has an Elastic Network Interface attached) with your load balancer, the load balancer will route traffic to the primary IP address of the instance (eth0). For more information on using Elastic Network Interfaces, go to Elastic Network Interfaces.

For detailed descriptions of the Elastic Load Balancing API actions, see Elastic Load Balancing API Reference.

Using the Command Line Interface

This example walks you through the process for creating a basic HTTP load balancer on Amazon VPC and registers Amazon EC2 instances with the newly created VPC load balancer. This example uses a default security group that is open to the internet on port 80.

To create a basic load balancer in your Amazon VPC

  1. Enter the command elb-create-lb as in the following example.

    PROMPT> elb-create-lb  MyVPCLoadBalancer --subnets subnet-4e05f721  --groups sg-b9ffedd5 --listener "lb-port=80,instance-port=8080,protocol=http,instance-protocol=http" 
                            
  2. Elastic Load Balancing returns the following:

    DNS-NAME  DNS-NAME 
    DNS-NAME  MyVPCLoadBalancer-2111276808.us-east-1a.elb.amazonaws.com

To register your Amazon EC2 instances with your VPC load balancer

You should only register instances that are in the Pending or Running state and are in a Virtual Private Cloud (VPC).

  1. Use the elb-register-instances-with-lb command as in the following example.

    PROMPT> elb-register-instances-with-lb  MyVPCLoadBalancer  --instances i-4f8cf126,i-0bb7ca62
  2. Elastic Load Balancing returns the following:

    INSTANCE  INSTANCE-ID
    INSTANCE  i-4f8cf126
    INSTANCE  i-0bb7ca62		
[Note]Note

When you register a multi-homed instance (an instance that has an Elastic Network Interface attached) with your load balancer, the load balancer will route traffic to the primary IP address of the instance (eth0). For more information on using Elastic Network Interfaces, go to Elastic Network Interfaces.

For detailed descriptions of the Elastic Load Balancing commands, see the Elastic Load Balancing Quick Reference Card.