Tutorial: Create a Network Load Balancer using the AWS CLI – Elastic Load Balancing
-
Use the create-load-balancer command to create a dualstack load balancer,
specifying a public subnet for each Availability Zone in which you launched
instances. You can specify only one subnet per Availability Zone.aws elbv2 create-load-balancer --name
my-load-balancer
--type network --subnets subnet-0e3f5cac72EXAMPLE
--ip-address-typedualstack
The output includes the Amazon Resource Name (ARN) of the load balancer, with
the following format:arn:aws:elasticloadbalancing:
us-east-2
:123456789012
:loadbalancer/net/my-load-balancer/1234567890123456
-
Use the create-target-group command to create a target group, specifying
the same VPC that you used for your EC2 instances.You must use either a TCP or TLS target group with your dualstack load
balancer.You can create IPv4 and IPv6 target groups to associate with dualstack load
balancers. The target group’s IP address type determines the IP version that the
load balancer will use to both communicate with, and check the health of, your
backend targets.IPv4 target groups support IP and instance type targets. IPv6 targets only
support IP targets.aws elbv2 create-target-group --name
my-targets
--protocol TCP --port 80 --vpc-id vpc-0598c7d356EXAMPLE
--ip-address-type[ipv4 or ipv6]
The output includes the ARN of the target group, with this format:
arn:aws:elasticloadbalancing:
us-east-2
:123456789012
:targetgroup/my-targets
/1234567890123456
-
Use the register-targets command to register your instances with your
target group:aws elbv2 register-targets --target-group-arn
targetgroup-arn
--targets Id=i-1234567890abcdef0
Id=i-0abcdef1234567890
-
Use the create-listener command to create a listener for your load balancer
with a default rule that forwards requests to your target group. Dualstack load
balancers must have TCP or TLS listeners.aws elbv2 create-listener --load-balancer-arn
loadbalancer-arn
--protocol TCP --port 80 \ --default-actions Type=forward,TargetGroupArn=targetgroup-arn
The output contains the ARN of the listener, with the following format:
arn:aws:elasticloadbalancing:
us-east-2
:123456789012
:listener/net/my-load-balancer
/1234567890123456
/1234567890123456
-
(Optional) You can verify the health of the registered targets for your target
group using this describe-target-health command:aws elbv2 describe-target-health --target-group-arn
targetgroup-arn