Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkLoadBalancedFargateService: (Passed subnets are not getting picked while creating the LoadBalancer) #29812

Open
SomnathDange opened this issue Apr 12, 2024 · 2 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@SomnathDange
Copy link

Describe the bug

var NLBService = new NetworkLoadBalancedFargateService(this, “NLBService”, new NetworkLoadBalancedFargateServiceProps {
                MemoryLimitMiB = 512,
                TaskDefinition = taskDefinition,
                Cluster = cluster,
                CircuitBreaker = new DeploymentCircuitBreaker {
                    Enable = true,
                    Rollback = true
                },
                ServiceName = “NLBService”,
                PublicLoadBalancer = false,

                TaskSubnets = new SubnetSelection {
                    Subnets = new [] { Subnet.FromSubnetId(this, "subnet", "subnet-12345678”9) }
                }
            });

This is my code subnet passed via SubnetSelection is getting passed to ECS service, but Loadbalancer picks all the subnets from VPC, and its not taking the subnets from the list which is passed in above code.

Expected Behavior

Expected behaviour is it should pick the passed subnet while creating the NetWork LoadBalancer.

Current Behavior

Passed subnets are not getting picked while creating the LoadBalancer

Reproduction Steps

Above code is producing the issue

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.134.0 (build 265d769)

Framework Version

No response

Node.js Version

v20.12.0

OS

Linux

Language

.NET

Language Version

6

Other information

No response

@SomnathDange SomnathDange added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Apr 12, 2024
@pahud
Copy link
Contributor

pahud commented Apr 12, 2024

According to this

const lbProps = {
vpc: this.cluster.vpc,
internetFacing,
};
const loadBalancer = props.loadBalancer ?? new NetworkLoadBalancer(this, 'LB', lbProps);

At this moment, the auto provisioned NLB will by default span multiple subnets based on the rule.

We probably need a PR to add a new option like nlbListenerOnTaskSubnets or something else that passes the subnet selection all the way to here.

Before that, a workaround is to use escape hatches to override the Subnets prop of the NLB.

Making this a p2, please help us prioritize by 👍 and we welcome PRs to move this forward.

@pahud pahud added p2 effort/medium Medium work item – several days of effort @aws-cdk/aws-ecs-patterns Related to ecs-patterns library and removed needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@SomnathDange
Copy link
Author

SomnathDange commented Apr 13, 2024

Let me add some more details:

The VPC has four private subnets, with two subnets in each availability zones. When attempting to create a NetworkLoadBalancedFargateService, an error occurs, stating "A load balancer cannot be attached to multiple subnets in the same Availability Zone." This is due to the presence of two subnets in one availability zone.

To address this issue, the SubnetSelection was specified for the NetworkLoadBalancedFargateService. By passing two subnets from different availability zones, the service was able to use the desired subnets(verifies in cloud formation template). However, when the Network Load Balancer was internally created by NetworkLoadBalancedFargateService, it selected all four subnets from the VPC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container @aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

2 participants