(elasticloadbalancingv2): cannot have more than one target group on a single NLB listener
See original GitHub issueNLB listeners currently allow for more than one target group to be added: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts#L33
However, there can only be one target group for an NLB listener since there can only be one default rule for an NLB listener: https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html
Reproduction Steps
import * as cdk from '@aws-cdk/core';
import * as ecs from '@aws-cdk/aws-ecs';
import * as elb from '@aws-cdk/aws-elasticloadbalancingv2';
import { Vpc } from '@aws-cdk/aws-ec2';
export class NlbTestStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new Vpc(this, 'Vpc');
const cluster = new ecs.Cluster(this, 'Cluster', {
vpc
});
const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
compatibility: ecs.Compatibility.FARGATE,
cpu: "1024",
memoryMiB: "2048",
});
const container = taskDefinition.addContainer('container', {
image: ecs.ContainerImage.fromRegistry('node'),
});
container.addPortMappings({ containerPort: 80 });
const service1 = new ecs.FargateService(this, 'Service1', {
cluster,
taskDefinition,
});
const service2 = new ecs.FargateService(this, 'Service2', {
cluster,
taskDefinition,
});
const lb = new elb.NetworkLoadBalancer(this, 'NLB', {
vpc,
})
const listener = lb.addListener('listener1', {
port: 80,
});
listener.addTargets('service1target', {
port: 80,
targets: [service1]
})
listener.addTargets('service2target', {
port: 80,
targets: [service2]
})
}
}
Deploying this stack results in the following CFN error:
Invalid request provided: CreateService error: The target group with targetGroupArn arn:aws:elasticloadbalancing:us-west-1:430030518091:targetgroup/NlbTe-NLBli-1XYX36JEGVQHP/010a21c45e3d17ea does not have an associated load balancer. (Service: Ecs, Status Code: 400, Request ID: 4f3d5f5f-9a56-4af9-8a2f-673267b35bb3, Extended Request ID: null)
What did you expect to happen?
What actually happened?
Environment
- CDK CLI Version : 1.77
- Framework Version: 1.77
- Node.js Version: v12.15.0
- OS : MacOS
- Language (Version): Typescript 3.8.3
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Target groups for your Network Load Balancers
Each target group is used to route requests to one or more registered targets. When you create a listener, you specify a target...
Read more >AWS Network LoadBalancer listener and the following target ...
I have two stack's aws.yaml and web.yaml . CF responds with the following error on execution: Internal error reported from downstream service ...
Read more >aws-cdk.aws-elasticloadbalancingv2 - PyPI
Every listener must have at least one target without conditions, which is where all requests that didn't match any of the conditions will...
Read more >ElasticLoadBalancingv2 — Boto3 Docs 1.26.36 documentation
If you attempt to create multiple listeners with the same settings, each call succeeds ... To route to one or more target groups,...
Read more >TargetGroup cannot be associated with more than one load ...
When a TargetGroup, LoadBalancer, and Listener are setup, if an update triggers a replace of the LoadBalancer the stack can't be updated.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
up ingress Failed deploy model due to failed to create listener rule: TargetGroupAssociationLimit: The following target groups cannot be associated with more than one load balancer: arn:aws:elasticloadbalancing:eu-central-1:12222222:targetgroup/k8s-default-monorepo-bafd567687/add252b99f892cc7 status code: 400, request id: 4aff53e2-9c52-4dc9-85d0-a8dbd84e5e21
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.