[英]How do I add Targets with specific port using aws-cdk to existing ApplicationTargetGroup
我有一個現有的 LoadBalancer 和 ApplicationTargetGroup,我正在嘗試添加一個自動縮放組作為目標,如下所示
const asg = new autoscaling.AutoScalingGroup(this, 'AutoScalingGroup', {
vpc,
machineImage,
instanceType: ec2.InstanceType.of(
ec2.InstanceClass.T3,
ec2.InstanceSize.MICRO
),
allowAllOutbound: true,
associatePublicIpAddress: true,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
keyName,
autoScalingGroupName,
desiredCapacity: 1,
healthCheck: autoscaling.HealthCheck.ec2({
grace: cdk.Duration.seconds(60),
}),
})
asg.userData.addCommands(...commands)
const tg = elbv2.ApplicationTargetGroup.fromTargetGroupAttributes(
this,
'TargetGroup',
{
targetGroupArn,
}
)
tg.addTarget(asg)
這一切都很好,除了注冊目標中的 ec2s 的端口是 80,但我需要它是一個不同的端口,我不確定如何使用現有的基礎設施來做到這一點
我正要開始研究一個類似的問題並且正在研究。 我遇到了這個可能會有所幫助
const alb = new elbv2.ApplicationLoadBalancer(this, 'alb', {
vpc,
internetFacing: true,
});
const listener = alb.addListener('Listener', {
port: 80,
open: true,
});
//create auto scaling group
const asg = new autoscaling.AutoScalingGroup(this, 'asg', {
vpc,
instanceType: ec2.InstanceType.of(
ec2.InstanceClass.T2,
ec2.InstanceSize.MICRO,
),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
userData,
minCapacity: 2,
maxCapacity: 3,
});
// add target to the ALB listener
listener.addTargets('default-target', {
port: 80,
targets: [asg],
healthCheck: {
path: '/',
unhealthyThresholdCount: 2,
healthyThresholdCount: 5,
interval: cdk.Duration.seconds(30),
},
});
看起來您想調查 ALB 偵聽器的配置。 希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.