There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DescribeTargetGroups
with an AWS SDK or CLI
The following code examples show how to use DescribeTargetGroups
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- CLI
-
- AWS CLI
-
Example 1: To describe a target group
The following
describe-target-groups
example displays details for the specified target group.aws elbv2 describe-target-groups \ --target-group-arns
arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067
Output:
{ "TargetGroups": [ { "TargetGroupArn": "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067", "TargetGroupName": "my-targets", "Protocol": "HTTP", "Port": 80, "VpcId": "vpc-3ac0fb5f", "HealthCheckProtocol": "HTTP", "HealthCheckPort": "traffic-port", "HealthCheckEnabled": true, "HealthCheckIntervalSeconds": 30, "HealthCheckTimeoutSeconds": 5, "HealthyThresholdCount": 5, "UnhealthyThresholdCount": 2, "HealthCheckPath": "/", "Matcher": { "HttpCode": "200" }, "LoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188" ], "TargetType": "instance", "ProtocolVersion": "HTTP1", "IpAddressType": "ipv4" } ] }
Example 2: To describe all target groups for a load balancer
The following
describe-target-groups
example displays details for all target groups for the specified load balancer. The example uses the--query
parameter to display only the target group names.aws elbv2 describe-target-groups \ --load-balancer-arn
arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188
\ --queryTargetGroups[*].TargetGroupName
Output:
[ "my-instance-targets", "my-ip-targets", "my-lambda-target" ]
For more information, see Target groups in the Applicaion Load Balancers Guide.
-
For API details, see DescribeTargetGroups
in AWS CLI Command Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. const client = new ElasticLoadBalancingV2Client({}); const { TargetGroups } = await client.send( new DescribeTargetGroupsCommand({ Names: [NAMES.loadBalancerTargetGroupName], }), );
-
For API details, see DescribeTargetGroups in AWS SDK for JavaScript API Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example describes the specified Target Group.
Get-ELB2TargetGroup -TargetGroupArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970'
Output:
HealthCheckEnabled : True HealthCheckIntervalSeconds : 30 HealthCheckPath : / HealthCheckPort : traffic-port HealthCheckProtocol : HTTP HealthCheckTimeoutSeconds : 5 HealthyThresholdCount : 5 LoadBalancerArns : {arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f} Matcher : Amazon.ElasticLoadBalancingV2.Model.Matcher Port : 80 Protocol : HTTP TargetGroupArn : arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/test-tg/a4e04b3688be1970 TargetGroupName : test-tg TargetType : instance UnhealthyThresholdCount : 2 VpcId : vpc-2cfd7000
-
For API details, see DescribeTargetGroups in AWS Tools for PowerShell Cmdlet Reference.
-