question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ecs-patterns/ApplicationLoadBalancedFargateService fails to deploy in VPC with multiple subnets in same AZ

See original GitHub issue

The ApplicationLoadBalancedFargateService construct (and possibly other related constructs) fails to deploy when there exist multiple public subnets in the same AZ. It appears that the construct selects all public subnets from the provided VPC by default.

Reproduction Steps

I was following the “ECS Example” described at https://docs.aws.amazon.com/cdk/latest/guide/ecs_example.html but utilizing an existing VPC (with 7 pre-existing public subnets) instead of creating a new VPC like the example prescribes.

Error Log

  7/16 | 10:00:14 AM | CREATE_FAILED        | AWS::ElasticLoadBalancingV2::LoadBalancer | DevStack/MyFargateService/LB (MyFargateServiceLBDE830E97) A load balancer cannot be attached to multiple subnets in the same Availability Zone (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: InvalidConfigurationRequest; Request ID: 4915531e-c85f-40f6-93ff-0a899d948d5e)
        new BaseLoadBalancer (/mnt/c/git-repos/atlassian-backup/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts:138:22)
        \_ new ApplicationLoadBalancer (/mnt/c/git-repos/atlassian-backup/node_modules/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts:64:5)
        \_ new ApplicationLoadBalancedServiceBase (/mnt/c/git-repos/atlassian-backup/node_modules/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts:300:81)
        \_ new ApplicationLoadBalancedFargateService (/mnt/c/git-repos/atlassian-backup/node_modules/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts:92:5)
        \_ new AtlassianBackupStack (/mnt/c/git-repos/atlassian-backup/lib/atlassian-backup-stack.ts:24:5)
        \_ Object.<anonymous> (/mnt/c/git-repos/atlassian-backup/bin/atlassian-backup.ts:14:15)
        \_ Module._compile (internal/modules/cjs/loader.js:778:30)
        \_ Module.m._compile (/mnt/c/git-repos/atlassian-backup/node_modules/ts-node/src/index.ts:814:23)
        \_ Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        \_ Object.require.extensions.(anonymous function) [as .ts] (/mnt/c/git-repos/atlassian-backup/node_modules/ts-node/src/index.ts:817:12)
        \_ Module.load (internal/modules/cjs/loader.js:653:32)
        \_ tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        \_ Function.Module._load (internal/modules/cjs/loader.js:585:3)
        \_ Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
        \_ main (/mnt/c/git-repos/atlassian-backup/node_modules/ts-node/src/bin.ts:226:14)
        \_ Object.<anonymous> (/mnt/c/git-repos/atlassian-backup/node_modules/ts-node/src/bin.ts:485:3)
        \_ Module._compile (internal/modules/cjs/loader.js:778:30)
        \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        \_ Module.load (internal/modules/cjs/loader.js:653:32)
        \_ tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        \_ Function.Module._load (internal/modules/cjs/loader.js:585:3)
        \_ Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
        \_ findNodeScript.then.existing (/home/fshields/.nvm/versions/node/v10.18.1/lib/node_modules/npm/node_modules/libnpx/index.js:268:14)

Environment

  • CDK Version : 1.21.1 (build 842cc5f)
  • Framework Version:
  • OS : Debian GNU/Linux 9 (stretch)
  • Language : TypeScript 3.7.5

Other


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:12
  • Comments:9

github_iconTop GitHub Comments

5reactions
xcrezdcommented, Oct 1, 2020

Workaround


    const albFargetService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
     ...
    });

    const cfnLoadBalancer = albFargetService.loadBalancer.node.defaultChild as CfnLoadBalancer
    cfnLoadBalancer.subnets = vpc.selectSubnets({ onePerAz: true, subnetType: SubnetType.PUBLIC}).subnetIds
1reaction
nkolatsiscommented, Oct 15, 2021

The following python work-around uses two approaches. The approach above and a subnet_ids approach. Use it depending on what you have available.

subnet_ids = ['subnet-1234', 'subnet-5678']
alb_fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(self, .....)

cfn_lb = alb_fargate_service.load_balancer.node.default_child
if not subnet_ids:
    cfn_lb.subnets = vpc.select_subnets(subnet_group_name=subnet_group_name, availability_zones=availability_zones, one_per_az=True).subnet_ids
else:
    cfn_lb.subnets = subnet_ids
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add or remove subnets for your Classic Load Balancer in a VPC
Select subnets from the same Availability Zones as your instances. If your load balancer is an internet-facing load balancer, you must select public...
Read more >
ELB failure - Multiple subnets in one AZ - Stack Overflow
P.S: Passing all the 6 subnets as a list fails the load balancer creation because LB somehow picks 2 subnets in the same...
Read more >
Quickstart: Create and use VPC networks - Google Cloud
Within a project, a subnet cannot have the same name as a VPC network unless it ... you will not be able to...
Read more >
When to create different subnets in AWS VPCs - Tom Gregory
Each IP in the subnet will have the same subnet prefix, ... split the range of IP addresses in the VPC into multiple...
Read more >
How to Build AWS VPC using Terraform - Step by Step
It is possible to have multiple subnets in the same AZ. ... An Internet Gateway is deployed and associated with the VPC to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found