在自定义放大资源内部部署内部时,为什么不是附加到目标组的负载平衡器?
我正在尝试使用CloudFormation CDK添加自定义AWS放大资源:在Fargate上运行的Grafana容器,由负载平衡器前面。使用L3 Construct ecs_patterns.applicationloadbalancedfargateservice(),这应该足够简单,但是无论我尝试什么,我都会继续遇到错误:“带有targetGrouparn [arn]的目标组没有相关的负载均衡器”。即使尝试在连接两者之前单独创建负载平衡器和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',
});
但不幸的是,这产生了相同的结果。
I'm attempting to add a custom AWS Amplify resource using the CloudFormation CDK: a Grafana container running on Fargate, fronted by a load balancer. This should be simple enough using the L3 construct ecs_patterns.applicationLoadBalancedFargateService() but no matter what I try I keep getting the error "The target group with targetGroupArn [arn] does not have an associated load balancer". Even when attempting to create the load balancer and Fargate service separately before connecting the two it seems that the target group just cannot be assigned the load balancer using addListener or anything else... the same error is also returned when using service.registerLoadBalancerTargets() as well.
I've gotten other custom resources to deploy but with this one I'm lost at this point; Is there more to the example than stated in the docs? Is there something Amplify specific I'm missing here?
Here's a snippet of my code if that helps:
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)
})
I'm new to the CDK and IaC but to my understanding everything after defining the scalable target is redundant but I'm still told the target group does not have an associated load balancer. I also tried attaching the service to a LB manually:
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',
});
But unfortunately this yielded the same result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终没有找到解决这个问题的解决方案。在放大项目之外构建基础设施时,负载平衡器如预期的那样旋转。
这些两个两个
I did not end up finding a resolution to this issue. When building the infrastructure outside of an Amplify project the load balancer spins right up as expected.
These two pages outline configuring the Amplify client libraries to work with infrastructure that wasn't deployed in conjunction with the Amplify CLI/Env. Taking this route also allows you to use the CDK V2 as opposed to the no longer developed V1 which is the only version Amplify officially accepts.