Created
April 5, 2024 04:41
-
-
Save edwardrf/83e552a0d9895639f993c319f0a6ccbe to your computer and use it in GitHub Desktop.
Getting ALB arn from TargetGroup Arn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"os" | |
"github.com/aws/aws-sdk-go-v2/config" | |
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" | |
) | |
func main() { | |
if len(os.Args) < 2 { | |
fmt.Printf("Usage: %v <listenerArn>", os.Args[0]) | |
os.Exit(1) | |
} | |
tgArn := os.Args[1] | |
ctx := context.Background() | |
cfg, err := config.LoadDefaultConfig(context.Background()) | |
if err != nil { | |
log.Fatalf("unable to load SDK config, %v", err) | |
} | |
svc := elbv2.NewFromConfig(cfg) | |
searchInput := &elbv2.DescribeTargetGroupsInput{TargetGroupArns: []string{tgArn}} | |
rulesOutput, err := svc.DescribeTargetGroups(ctx, searchInput) | |
if err != nil { | |
log.Fatalf("failed to run describe target group: %v", err) | |
} | |
for _, tg := range rulesOutput.TargetGroups { | |
fmt.Printf("TargetGroupArn: %v -> LoadBalancer %v\n", *tg.TargetGroupArn, tg.LoadBalancerArns) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment