我们是否可以将新的应用程序目标组附加到现有的自动缩放组?

2024-09-30 08:29:31 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有方法将新的应用程序目标组附加到现有的自动缩放组

在我下面的代码中,我试图尝试它,但它似乎不起作用

lb = aws_cdk.aws_elasticloadbalancingv2.ApplicationLoadBalancer(self, "ServiceApplicationLB", vpc=vpc, internet_facing=True, security_group=sg)

#Fetching AutoScalingGroup ID from Service Stack
AsgNameOutputs = boto3.Session().client("cloudformation").describe_stacks(StackName="Service")["Stacks"][0]["Outputs"]
AsgNames=[]

for Output in AsgNameOutputs:
    if Output["OutputKey"].startswith("AutoScalingGroupName"):
        AsgNames.append(Output["OutputValue"])

print("AsgNames: ", AsgNames)

listener = lb.add_listener("Listener", port=80)

applicationTargetGroup = listener.add_targets("Target", port=8080,
    health_check={"path": "/ping", "interval": Duration.seconds(30), "port": "8080"})

for AsgName in AsgNames:
    asg = aws_cdk.aws_autoscaling.AutoScalingGroup.from_auto_scaling_group_name(self, AsgName, auto_scaling_group_name=AsgName)     # FIX ME
    #Above line is returning IAutoScalingGroup. Instead I need AutoScalingGroup here so to call the attach_to_application_target_group method

    aws_cdk.aws_autoscaling.AutoScalingGroup.attach_to_application_target_group(asg, target_group=applicationTargetGroup)    #FIX ME

Tags: tofromselfawstargetoutputportgroup

热门问题