Creating a Network Load Balancer
Learn how to create an Network Load Balancer in the Amazon Web Services Management Console.
Configure a target group for routing
In this section, you create a target group for your load balancer and the health check criteria for targets that are registered within that group.
Each target group is used to route requests to one or more registered targets. When a rule condition is met, traffic is forwarded to the corresponding target group.
Your load balancer distributes traffic between the targets that are registered to its target groups. When you associate a target group to an Amazon ECS service, Amazon ECS automatically registers and deregisters containers with your target group. Because Amazon ECS handles target registration, you do not add targets to your target group at this time.
To create a target group using the console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
On the navigation pane, under LOAD BALANCING, choose Target Groups.
-
Choose Create target group.
-
For Choose a target type,Instances to register targets by instance ID, IP addresses to register targets by IP address, or Lambda function to register a Lambda function as a target.
Important
If your service's task definition uses the
awsvpc
network mode (which is required for the Fargate launch type), you must choose IP addresses as the target type This is because tasks that use theawsvpc
network mode are associated with an elastic network interface, not an Amazon EC2 instance. -
For Target group name, enter a name for the target group. This name must be unique per region per account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen.
-
(Optional) For Protocol and Port, modify the default values as needed.
-
If the target type is IP addresses, choose IPv4 as the IP address type, otherwise skip to the next step.
Note that only targets that have the selected IP address type can be included in this target group. The IP address type cannot be changed after the target group is created.
-
For VPC, select a virtual private cloud (VPC). Note that for IP addresses target types, the VPCs available for selection are those that support the IP address type that you chose in the previous step.
-
(Optional) For Protocol version, modify the default value as needed.
-
(Optional) In the Health checks section, modify the default settings as needed.
-
(Optional) Add one or more tags as follows:
-
Expand the Tags section.
-
Choose Add tag.
-
Enter the tag key and the tag value.
-
-
Choose Next.
-
Register your targets with an instance ID or an IP address.
Important
If your service's task definition uses the
awsvpc
network mode (which is required for the Fargate launch type), you must chooseip
as the target type, notinstance
. This is because tasks that use theawsvpc
network mode are associated with an elastic network interface, not an Amazon EC2 instance.You cannot register instances by instance ID if they have the following instance types: C1, CC1, CC2, CG1, CG2, CR1, G1, G2, HI1, HS1, M1, M2, M3, and T1. You can register instances of these types by IP address.
-
Choose Create target group.
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 the frontend (client to load balancer) connections, and protocol and a port for the backend (load balancer to backend instance) connections.
To create a Network Load Balancer
-
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, choose Internet-facing or Internal.
An internet-facing load balancer routes requests from clients to targets over the internet. An internal load balancer routes requires private IP addresses for targets.
-
For IP address type, choose the IP adressing for the containers subnets.
-
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 Listeners and routing, keep the default protocol and port, and select your 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.
-
For Default action, select the target group that you created.
-
(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.
Create an Amazon ECS service
After your load balancer and target group are created, you can specify the target group in a service definition when you create a service. When each task for your service is started, the container and port combination specified in the service definition is registered with your target group and traffic is routed from the load balancer to that container. For more information, see Creating a service using the console.