【发布时间】:2021-05-26 19:32:50
【问题描述】:
我有一个弹性负载均衡器为 EC2 实例提供流量。我有一个在 443 端口上运行的应用程序,它运行得很好。
现在我想在 EC2 实例的 444 端口上运行另一个应用程序。我希望能够通过访问端口 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 中修复它...
【问题讨论】:
标签: amazon-web-services amazon-elb aws-cdk