Tutorial: Create a Classic Load Balancer - Elastic Load Balancing

Tutorial: Create a Classic Load Balancer

This tutorial provides a hands-on introduction to Classic Load Balancers through the AWS Management Console, a web-based interface. You'll create a load balancer that receives public HTTP traffic and sends it to your EC2 instances.

Before you begin

  • Complete the steps in Prepare your VPC and EC2 instances.

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

  • Install a web server, such as Apache or Internet Information Services (IIS), on each instance, enter its DNS name into the address field of an internet-connected web browser, and verify that the browser displays the default page of the server.

Create a Classic Load Balancer using the AWS Management Console

New EC2 experience

Use the following procedure to create your Classic Load Balancer. Provide basic configuration information for your load balancer, such as a name and scheme. Then provide information about your network, and the listener that routes traffic to your instances.

To create a Classic Load Balancer
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation bar, choose a Region for your load balancer. Be sure to select the same Region that you selected for your EC2 instances.

  3. On the navigation pane, under Load Balancing, choose Load Balancers.

  4. Choose Create Load Balancer.

  5. Expand the Classic Load Balancer section, then choose Create.

  6. Basic configuration

    1. For Load balancer name, type a name for your load balancer.

      The name of your Classic Load Balancer must be unique within your set of Classic Load Balancers for the Region, can have a maximum of 32 characters, can contain only alphanumeric characters and hyphens, and must not begin or end with a hyphen.

    2. For Scheme, select Internet-facing.

  7. Network mapping

    1. For VPC, select the same VPC that you selected for your instances.

    2. For Mappings, first select an Availability Zone, then choose a public subnet from its available subnets. You can only select one subnet per Availability Zone. To improve the availability of your load balancer, select more than one Availability Zone and subnet.

  8. Security groups

    1. For Security groups, select an existing security group that is configured to allow the required HTTP traffic on port 80.

  9. Listeners and routing

    1. For Listener, ensure the protocol is HTTP and the port is 80.

    2. For Instance, ensure the protocol is HTTP and the port is 80.

  10. Health checks

    1. For Ping Protocol, ensure the protocol is HTTP.

    2. For Ping Port, ensure the port is 80.

    3. For Ping Path, ensure the path is /.

    4. For Advanced health check settings, use the default values.

  11. Instances

    1. Select Add instances, to bring up the instance selection screen.

    2. Under Available instances, you can select from the current instances that are available to the load balancer, based on the current network settings.

    3. After you're satisfied with your selections, select Confirm to add the instances to be registered to the load balancer.

  12. Attributes

    1. For Enable cross-zone load balancing, Enable connection draining, and Timeout (draining interval) keep the default values.

  13. Load balancer tags (optional)

    1. The Key field is required.

    2. The Value field is optional.

    3. To add another tag, select Add new tag then input your values into the Key field, and optionally the Value field.

    4. To remove an existing tag, select Remove next to the tag you want to remove.

  14. Summary and creation

    1. If you need to change any settings, select Edit next to the setting needing to be changed.

    2. After you're satisfied with all the settings shown in the summary, select Create load balancer to begin creation of your load balancer.

    3. On the final creation page, select View load balancer to view your load balancer in the Amazon EC2 console.

  15. Verify

    1. Select your new load balancer.

    2. On the Target instances tab, check the Health status column. After at least one of your EC2 instances is In-service, you can test your load balancer.

    3. In the Details section, copy the load balancers DNS name, which would look similar to my-load-balancer-1234567890.us-east-1.elb.amazonaws.com.

    4. Paste your load balancers DNS name into the address field of a public internet connected web browser. If your load balancer is functioning correctly, you will see the default page of your server.

  16. Delete (optional)

    1. If you have a CNAME record for your domain that points to your load balancer, point it to a new location and wait for the DNS change to take effect before deleting your load balancer.

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

    3. Select the load balancer.

    4. Choose Actions, Delete load balancer.

    5. When prompted for confirmation, type confirm then select Delete.

    6. After you delete a load balancer, the EC2 instances that were registered with the load balancer continue to run. You will be billed for each partial or full hour that they continue running. When you no longer need an EC2 instance, you can stop or terminate it to prevent incurring additional charges.

Old EC2 experience
Step 1: Select a load balancer type

Elastic Load Balancing supports different types of load balancers. For this tutorial, you create a Classic Load Balancer.

To create a Classic Load Balancer
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. On the navigation bar, choose a Region for your load balancer. Be sure to select the same Region that you selected for your EC2 instances.

  3. On the navigation pane, under LOAD BALANCING, choose Load Balancers.

  4. Choose Create Load Balancer.

  5. For Classic Load Balancer, choose Create.

Step 2: Define your load balancer

You must provide a basic configuration 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 a port for back-end (load balancer to instance) connections. In this tutorial, you configure a listener that accepts HTTP requests on port 80 and sends them to your instances on port 80 using HTTP.

To define your load balancer and listener
  1. For Load Balancer name, type a name for your load balancer.

    The name of your Classic Load Balancer must be unique within your set of Classic Load Balancers for the Region, can have a maximum of 32 characters, can contain only alphanumeric characters and hyphens, and must not begin or end with a hyphen.

  2. For 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 choose the subnets for your load balancer, select Enable advanced VPC configuration.

  4. Leave the default listener configuration.

    
								Define your load balancer
  5. [EC2-VPC] For Available subnets, select at least one available public subnet using its add icon. The subnet is moved under Selected subnets. To improve the availability of your load balancer, select more than one public subnet.

    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 the user interface to select subnets.

    You can add at most one subnet per Availability Zone. If you select a subnet from an Availability Zone where there is already an selected subnet, this subnet replaces the currently selected subnet for the Availability Zone.

    
								Select Subnets
  6. Choose Next: Assign Security Groups.

Step 3: 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. Type 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. Choose Next: Configure Security Settings.

  4. For this tutorial, you are not using a secure listener. Choose Next: Configure Health Check to continue to the next step.

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, leave Ping Protocol set to HTTP and Ping Port set to 80.

  2. For Ping Path, 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.

    
								Configure Health Check
  3. For Advanced Details, leave the default values.

  4. Choose 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. Leave cross-zone load balancing and connection draining enabled.

  3. Choose 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 Classic 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, choose Create Tag and specify a key and a value for the tag.

  3. After you are finished adding tags, choose 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 create and test your load balancer
  1. On the Review page, choose Create.

  2. After you are notified that your load balancer was created, choose Close.

  3. Select your new load balancer.

  4. 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 Troubleshoot a Classic Load Balancer: Instance registration.

  5. After at least one of your EC2 instances is in service, you can test your load balancer. Copy the string from DNS name (for example, my-load-balancer-1234567890.us-west-2.elb.amazonaws.com) and paste it into the address field of an internet-connected web browser. If your load balancer is working, you see the default page of your 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. Note that deleting a load balancer does not affect the instances registered with the load balancer.

To delete your load balancer
  1. If you have a CNAME record for your domain that points to your load balancer, point it to a new location and wait for the DNS change to take effect before deleting your load balancer.

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

  3. On the navigation pane, under Load Balancing, choose Load Balancers.

  4. Select the load balancer.

  5. Choose Actions, Delete.

  6. When prompted for confirmation, choose Yes, Delete.

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