aws-cdk - 将目标组分配给现有的 ASG
问题描述
我有以下代码:
this.nlb = new NetworkLoadBalancer(
this.parent,
this.id,
{
vpc: this.vpc,
vpcSubnets: {
subnets: subnets,
},
internetFacing: true,
}
);
const targetGroup = new NetworkTargetGroup(
this.parent,
`${this.id}-TG-${listenerPort}-${targetPort}`,
{
port: targetPort,
protocol: Protocol.TCP_UDP,
targetType: TargetType.INSTANCE,
vpc: this.vpc,
},
);
const listener = this.nlb.addListener(`${this.id}-TG-${listenerPort}`, {
port: listenerPort,
protocol: Protocol.TCP_UDP,
defaultTargetGroups: [
targetGroup,
]
});
它按预期工作,创建网络负载均衡器、目标组和绑定到 NLB 的侦听器。
我无法完成的是将这个新的 TG 添加到现有的 AutoScaling 组中。
ASG 由另一个项目管理,但我需要将我的 TG 添加到它。
如果我尝试:
const asg = AutoScalingGroup.fromAutoScalingGroupName(
this.parent,
`${this.id}-ASG-${listenerPort}-${targetPort}`,
config.autoScalingGroup, // This has the name of the autoscaling group
);
const targetGroup = new NetworkTargetGroup(
this.parent,
`${this.id}-TG-${listenerPort}-${targetPort}`,
{
port: targetPort,
protocol: Protocol.TCP_UDP,
targets: [asg], // Add the imported ASG as target
targetType: TargetType.INSTANCE,
vpc: this.vpc,
},
);
它不起作用,因为导入的 SG 没有提供正确的方法。
解决方案
推荐阅读
- c++ - 将字符串拆分为由换行符分隔的向量
- c++ - 链接错误 Cython
- pyspark - 无法在独立火花集群中运行火花提交
- java - 引起:java.lang.IllegalStateException:同一实体的多个表示
- r - tidymodels 调优中超参数网格搜索功能的参数
- flutter - 如何以半屏宽高比或 const 高度显示相机不起作用
- python - 为推荐系统创建for循环?
- python - 使用python检查给定单词的不可预测类型的文件
- javascript - 未捕获的 TypeError:Vehicles_1.Car 不是构造函数 | 打字稿到 JavaScript
- django - DjangoTemplate 中的 DateField 格式