Getting started with Network Load Balancers
This tutorial provides a hands-on introduction to Network Load Balancers through the Amazon Web Services Management Console, a web-based interface. To create your first Network Load Balancer, complete the following steps.
Contents
For demos of common load balancer configurations, see Elastic Load Balancing Demos
Prerequisites
-
Decide which Availability Zones you will use for your EC2 instances. Configure your virtual private cloud (VPC) with at least one public subnet in each of these Availability Zones. These public subnets are used to configure the load balancer. You can launch your EC2 instances in other subnets of these Availability Zones instead.
-
Launch at least one EC2 instance in each Availability Zone. Ensure that the security groups for these instances allow TCP access from clients on the listener port and health check requests from your VPC. For more information, see Target security groups.
Step 1: Create a target group for your Network Load Balancer
Create a target group, which is used in request routing. The rule for your listener routes requests to the registered targets in this target group. The load balancer checks the health of targets in this target group using the health check settings defined for the target group.
To configure your target group using the console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
In the navigation pane, under Load Balancing, choose Target Groups.
-
Choose Create target group.
-
Keep the target type as instances.
-
For Target group name, enter a name for the new target group.
-
For Protocol, choose TCP, and for Port, choose 80.
-
For VPC, select the VPC that contains your instances.
-
For Health checks, keep the default settings.
-
Choose Next.
-
On the Register targets page, complete the following steps. This is an optional step to create a target group. However, you must register your targets if you want to test your load balancer and ensure that it is routing traffic to your targets.
-
For Available instances, select one or more instances.
-
Keep the default port 80, and choose Include as pending below.
-
-
Choose Create target group.
Step 2: Create a Network Load Balancer
To create a Network Load Balancer, you must first provide basic configuration information for your load balancer, such as a name, scheme, and IP address type. Then provide information about your network, and one or more listeners. A listener is a process that checks for connection requests. It is configured with a protocol and a port for connections from clients to the load balancer. For more information about supported protocols and ports, see Listener configuration.
To create a Network Load Balancer using the console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
On the navigation bar, choose a Region for your load balancer. Be sure to choose the same Region that you used for your EC2 instances.
-
In the navigation pane, under Load Balancing, choose Load Balancers.
-
Choose Create load balancer.
-
For Network Load Balancer, choose Create.
-
For Load balancer name, enter a name for your load balancer. For example,
my-nlb
. -
For Scheme and IP address type, keep the default values.
-
For Network mapping, select the VPC that you used for your EC2 instances. For each Availability Zone that you used to launch your EC2 instances, select the Availability Zone and then select one public subnet for that Availability Zone.
By default, Amazon assigns an IPv4 address to each load balancer node from the subnet for its Availability Zone. Alternatively, when you create an internet-facing load balancer, you can select an Elastic IP address for each Availability Zone. This provides your load balancer with static IP addresses.
-
For Security groups, we preselect the default security group for your VPC. You can select other security groups as needed. If you don't have a suitable security group, choose Create a new security group and create one that meets your security needs. For more information, see Create a security group in the Amazon VPC User Guide.
Warning
If you don't associate any security groups with your load balancer now, you can't associate them later on.
-
For Listeners and routing, keep the default protocol and port, and select the target group from the list. This configures a listener that accepts TCP traffic on port 80 and forwards traffic to the selected target group by default.
-
(Optional) Add tags to categorize your load balancer. Tag keys must be unique for each load balancer. Allowed characters are letters, spaces, numbers (in UTF-8), and the following special characters: + - = . _ : / @. Do not use leading or trailing spaces. Tag values are case-sensitive.
-
Review your configuration, and choose Create load balancer. A few default attributes are applied to your load balancer during creation. You can view and edit them after creating the load balancer. For more information, see Load balancer attributes.
Step 3: Test your Network Load Balancer
After creating the Network Load Balancer, verify that it's sending traffic to your EC2 instances.
To test your load balancer
-
After you are notified that your load balancer was created successfully, choose Close.
-
In the navigation pane, under Load Balancing, choose Target Groups.
-
Select the newly created target group.
-
Choose Targets and verify that your instances are ready. If the status of an instance is
initial
, it's probably because the instance is still in the process of being registered, or it has not passed the minimum number of health checks to be considered healthy. After the status of at least one instance ishealthy
, you can test your load balancer. -
In the navigation pane, under Load Balancing, choose Load Balancers.
-
Select the name of the newly created load balancer to open its details page.
-
Copy the DNS name of the load balancer (for example, my-load-balancer-1234567890abcdef.elb.us-west-2.amazonaws.com.cn). Paste the DNS name into the address field of an internet-connected web browser. If everything is working, the browser displays the default page of your server.
Step 4: (Optional) Delete your Network 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 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 targets registered with the load balancer. For example, your EC2 instances continue to run.
To delete your load balancer using the console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
In the navigation pane, under Load Balancing, choose Load Balancers.
-
Select the checkbox for the load balancer, and choose Actions, Delete.
-
When prompted for confirmation, enter
confirm
and choose Delete.