Amazon Web Services (AWS) - Create Application Load Balancer (ALB) Target Group using the AWS CLI

by
Jeremy Canfield |
Updated: May 13 2024
| Amazon Web Services (AWS) articles
Let's say you have two or more EC2 instances that are producing web apps. An application load balancer can be used to load balance the requests for the web app.
First and foremost, let's create a Target Group that will contain the EC2 instances. A Target Group contains:
- One or more EC2 instances using the EC2 instances ID
- One or more EC2 instances via IP address
- One or more EC2 instances via Lambda
- One or more Application Load Balancers (in other words, a group of Application Load Balancers)
For example, if using the AWS CLI, the aws ec2 describe-vpcs command can be used to the the ID of the Virtual Private Cloud (VPC) you want the Target Group to be in.
~]$ aws ec2 describe-vpcs --query 'Vpcs[?CidrBlock==`172.31.0.0/16`]' | grep "VpcId"
"VpcId": "vpc-123abd654dsf356s1",
And then the aws elbv2 create-target-group command can be used to create the Target Group. In this example, since --target-type instance was used, this Target Group will contain one or more EC2 instances.
aws elbv2 create-target-group --name my-target-group --protocol HTTP --port 80 --target-type instance --vpc-id vpc-014d2fcfa335d3c01
Did you find this article helpful?
If so, consider buying me a coffee over at