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

aws_ecs_patterns: ApplicationLoadBalancedFargateService does not allow multiple services to connect to the same load balancer #32958

Open
1 task
bytesnz-doc opened this issue Jan 15, 2025 · 1 comment
Labels
@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 feature-request A feature should be added or improved. p2

Comments

@bytesnz-doc
Copy link

Describe the bug

(Reopening of #24975)

The ApplicationLoadBalancedFargateService and ApplicationLoadBalancedServiceBase classes do not allow for multiple services to be created against the same load balancer. An example repo is https://gitlab.com/bytesnz/fargate-services-fail/-/blob/main/index.ts#L47 based off https://github.com/aws-samples/aws-cdk-examples/tree/main/typescript/application-load-balancer. The cause is a hardcoded name for the listener of PublicListener.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

ApplicationLoadBalancedFargateService and ApplicationLoadBalancedServiceBase classes use a unique name for the listener and cdk synth generates that stack correctly and stack is able to be deployed

Current Behavior

cdk synth throws an error

/projects/node_modules/constructs/src/construct.ts:430
      throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
            ^
Error: There is already a Construct with name 'PublicListener' in ApplicationLoadBalancer [NZTCSLoadBalancer]
    at Node.addChild (/projects/node_modules/constructs/src/construct.ts:430:13)
    at new Node (/projects/node_modules/constructs/src/construct.ts:71:17)
    at new Construct (/projects/node_modules/constructs/src/construct.ts:482:17)
    at new Resource (/projects/node_modules/aws-cdk-lib/core/lib/resource.js:1:1309)
    at new BaseListener (/projects/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-listener.js:1:1721)
    at new ApplicationListener (/projects/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-listener.js:1:3663)
    at ApplicationLoadBalancer.addListener (/projects/node_modules/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.js:1:6005)
    at new ApplicationLoadBalancedServiceBase (/projects/node_modules/aws-cdk-lib/aws-ecs-patterns/lib/base/application-load-balanced-service-base.js:1:4013)
    at new ApplicationLoadBalancedFargateService (/projects/node_modules/aws-cdk-lib/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.js:1:864)
    at new BackEnd (/projects/src/stacks/backEnd.ts:79:23)

Reproduction Steps

  1. Clone the repo https://gitlab.com/bytesnz/fargate-services-fail
  2. Install node dependencies
  3. Try to synth or deploy with CDK

Possible Solution

I was wondering if the id could be something like id + 'Listener' instead of 'PublicListener'. Can do a PR for, but there are a few other ids that might need the same treatment.

Additional Information/Context

No response

CDK CLI Version

2.175.1

Framework Version

2.175.1

Node.js Version

22

OS

Ubuntu

Language

TypeScript

Language Version

5.1.6

Other information

No response

@bytesnz-doc bytesnz-doc added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 15, 2025
@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Jan 15, 2025
@pahud pahud self-assigned this Jan 16, 2025
@pahud pahud added feature-request A feature should be added or improved. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 16, 2025
@pahud pahud removed their assignment Jan 16, 2025
@pahud
Copy link
Contributor

pahud commented Jan 16, 2025

Yes, this is a high level L3 construct which is opinionated and may not fit all use cases.

We should explore if we could gracefully build this feature upon the existing construct and not adding breaking changes.

We welcome PRs and please help us prioritize with 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@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 feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants