我正在尝试使用CloudFormation CDK添加一个自定义AWS扩容资源:一个运行在Fargate上的Grafana容器,由一个负载均衡器作为前端。使用ecs_patterns.applicationLoadBalancedFargateService()构造L3应该非常简单,但是无论我尝试什么,我都会得到错误“带有targetGroupArn的目标组没有关联的负载均衡器”。即使在试图在连接两个负载均衡器和Fargate服务之前分别创建负载均衡器和Fargate服务时,似乎也无法使用addListener或其他任何方法为目标组分配负载均衡器。在使用service.registerLoadBalancerTargets()时也会返回相同的错误。
我还需要部署其他自定义资源,但在这一点上我已经迷失了方向;这个例子是否比在医生们中所描述的更多呢?有什么东西是我遗漏的吗?
下面是我的代码片段,如果这有帮助的话:
const vpc = new ec2.Vpc(this, 'MarketVpc', { maxAzs: 2 }); //LB requires two Azs
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
const grafana = new ecs_patterns.ApplicationLoadBalancedFargateService(this, "Grafana", {
cluster,
cpu: 1024,
memoryLimitMiB: 2048,
loadBalancerName: "GrafanaLB",
circuitBreaker: {rollback: true},
taskImageOptions: {
containerName: 'grafana',
containerPort: 3000,
image: ecs.ContainerImage.fromAsset("./Amplify/backend/custom/timestream/grafana")
},
publicLoadBalancer: true,
targetProtocol: elbv2.ApplicationProtocol.HTTP,
protocol: elbv2.ApplicationProtocol.HTTP,
});
const scalableTarget = grafana.service.autoScaleTaskCount({
minCapacity: 1,
maxCapacity: 1
});
const listener = grafana.loadBalancer.addListener("grafanaListener",{
protocol: elbv2.ApplicationProtocol.HTTP,
defaultTargetGroups: [grafana.targetGroup]
})
grafana.service.registerLoadBalancerTargets({
containerName: 'grafana',
containerPort: 3000,
newTargetGroupId: 'ECSTargetGroup',
listener: ecs.ListenerConfig.applicationListener(listener)
})我是CDK和IaC的新手,但据我所知,定义可伸缩目标之后的一切都是多余的,但我仍然被告知目标组没有关联的负载均衡器。我还尝试手动将服务附加到LB上:
const grafanaTask = new ecs.TaskDefinition(this, 'WorkerTask', {
compatibility: ecs.Compatibility.FARGATE,
cpu: '1024',
memoryMiB: '2048'
});
const container = grafanaTask.addContainer('grafana', {
image: ecs.ContainerImage.fromAsset('./Amplify/backend/custom/timestream/grafana'),
environment: {
dbARN: db.attrArn, //convert to timestream plugin stuff
database: table.databaseName,
table: table.tableName
},
containerName: 'grafana'
})
container.addPortMappings({containerPort: 3000})
const grafana = new ecs.FargateService(this, "Grafana", { cluster, taskDefinition:grafanaTask });
const loadBalancer = new elbv2.ApplicationLoadBalancer(this, "GrafanaLB",{
vpc,
deletionProtection: false,
internetFacing: true
})
const listener = loadBalancer.addListener("grafanaListener",{ protocol: elbv2.ApplicationProtocol.HTTP })
grafana.registerLoadBalancerTargets({
containerName: 'grafana',
containerPort: 3000,
newTargetGroupId: 'ECSTargetGroup',
listener: ecs.ListenerConfig.applicationListener(listener)
})
new CfnOutput(this, 'GrafanaLink', {
value: grafana.loadBalancer.loadBalancerDnsName,
description: 'Grafana DNS Name',
});但不幸的是,这也产生了同样的结果。
https://stackoverflow.com/questions/72354382
复制相似问题