Search⌘ K
AI Features

Registering Targets

Explore how to register WordPress instances with a target group for load balancing using AWS CLI. Understand how to retrieve ARNs, format instance IDs, and create listeners to forward HTTP traffic. This lesson guides you through deploying a scalable and highly available WordPress application with load balancing on AWS.

The next step is to register targets with the target group. This assigns targets (WordPress instances in our case) to the target group so the load balancer can later address them all together.

The elbv2 register-targets command needs the following parameters:

  • --target-group-arn to specify the target group.

  • --targets to specify the targets (our WordPress instances). To specify instances, we can use the Id=<instance id> syntax. Other options instead of Id are ip for an IP address, lambda for an AWS Lambda function (we will not cover those), and alb for another load balancer (an Application Load Balancer to be precise).

We can list multiple targets separated by a space, so it looks like this:

Shell
aws elbv2 register-targets \
--target-group-arn <target-group-arn> \
--targets Id=<wordpress-instance-id1> Id=<wordpress-instance-id2>

To get the <target-group-arn> directly from our target group via its name, we can use elbv2 describe-target-groups with the --names parameter and filter the output. This is very similar to the other describe commands we have used already.

It looks like this:

Shell
aws elbv2 describe-target-groups \
--names wordpress-instances \
--query 'TargetGroups[*].TargetGroupArn' \
--output text

We can then insert this into the elbv2 register-targets command to pass the --target-group-arn parameter to get the following: