Amazon web services 如何为CDK中的两个不同端口配置ELB?

Amazon web services 如何为CDK中的两个不同端口配置ELB?,amazon-web-services,amazon-elb,aws-cdk,Amazon Web Services,Amazon Elb,Aws Cdk,我有一个弹性负载平衡器为EC2实例提供流量服务。我有一个应用程序在端口443上运行,它运行得很好 现在我想在端口444上的EC2实例上运行另一个应用程序。我希望能够通过点击端口443运行第一个应用程序,通过点击端口444运行第二个应用程序 不知何故,我无法将端口444添加到CDK中的负载平衡器。我正在做这样的事情 const appLoadbalancer = new elbv2.ApplicationLoadBalancer(this, `${props.type}AppLoadBalanc

我有一个弹性负载平衡器为EC2实例提供流量服务。我有一个应用程序在端口443上运行,它运行得很好

现在我想在端口444上的EC2实例上运行另一个应用程序。我希望能够通过点击端口443运行第一个应用程序,通过点击端口444运行第二个应用程序

不知何故,我无法将端口444添加到CDK中的负载平衡器。我正在做这样的事情

 const appLoadbalancer = new elbv2.ApplicationLoadBalancer(this, `${props.type}AppLoadBalancer`, {
            vpc: vpc,
            vpcSubnets: subnets,
            internetFacing: true,
        });

        const httpsListener = appLoadbalancer.addListener(`${props.type}HTTPSListener`, {
            port: 443,
            open: true,
            certificates: [props.certificate]
        });

        httpsListener.addTargets(`${props.type}HTTPSTarget`, {
            port: 443,
            targets: [autoscalingGroup],
            healthCheck: {
                enabled: true,
                healthyHttpCodes: "200,302"
            }
        });

        const httpsListener2 = appLoadbalancer.addListener(`${props.type}HTTPSListener2`, {
            port: 444,
            protocol: elbv2.ApplicationProtocol.HTTPS,
            open: true,
            certificates: [props.certificate]
        });

        httpsListener2.addTargets(`${props.type}HTTPSTarget2`, {
            port: 444,
            protocol: elbv2.ApplicationProtocol.HTTPS,
            targets: [autoscalingGroup],
            healthCheck: {
                enabled: true,
                healthyHttpCodes: "200,302"
            }
        });
如果只为端口443设置,则一切正常。但当我尝试上述方法时,我得到了如下结果:

Error: Cannot add AutoScalingGroup to 2nd Target Group

我不知道这是什么意思,以及如何在cdk中修复它…

我最终得到了这样一个解决方案:

 const appLoadbalancer = new elbv2.ApplicationLoadBalancer(this, `${props.type}AppLoadBalancer`, {
            vpc: vpc,
            vpcSubnets: subnet,
            internetFacing: true,
        });

        const tg1 = new elbv2.ApplicationTargetGroup(this, "tg1", {
            vpc: vpc,
            protocol: elbv2.ApplicationProtocol.HTTPS})
        const tg2 = new elbv2.ApplicationTargetGroup(this, "tg2", {vpc: vpc,
        protocol: elbv2.ApplicationProtocol.HTTPS, port: 444})

        const httpsListener = appLoadbalancer.addListener(`${props.type}HTTPSListener`, {
            port: 443,
            protocol: elbv2.ApplicationProtocol.HTTPS,
            open: true,
            certificates: [props.certificate]
        });
        httpsListener.addTargetGroups("RestTarget", {
            targetGroups: [tg1]
        });

        const httpsListener2 = appLoadbalancer.addListener(`${props.type}HTTPSListener2`, {
            port: 444,
            protocol: elbv2.ApplicationProtocol.HTTPS,
            open: true,
            certificates: [props.certificate]
        });
        httpsListener2.addTargetGroups("RestTarget", {
            targetGroups: [tg2]
        });

        const ServiceAsg = autoscalingGroup.node.defaultChild as autoscaling.CfnAutoScalingGroup
        ServiceAsg.targetGroupArns = [tg1.targetGroupArn, tg2.targetGroupArn]