-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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-ecspatterns): Support multi-targetgroup applications on different containers #24013
Comments
ApplicationMultipleTargetGroupsFargateService also seems to have the same problem. taskDefinition.addContainer('second', { const fargateService = new ecs_patterns.ApplicationMultipleTargetGroupsFargateService(this, 'MyFargateService', { it will generate CF template as which will result in deploy error as it is complaining TCP host port '8002' is mapped multiple times in task. Seems like when using the ApplicationMultipleTargetGroupsFargateService construct, you can specify an array of ApplicationTargetProps objects to create multiple target groups. Each ApplicationTargetProps object specifies the container name and port to use for the target group. However, the construct incorrectly uses the first containerPort value specified in the array for all target groups, instead of using the containerPort value specified for each individual target group. As a result, the CloudFormation template generated by the CDK has the wrong containerPort values assigned to each target group, which can cause issues when the service is deployed. |
Describe the feature
The ApplicationMultipleTargetGroupsEc2Service module only passes in the default task definition container name
https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/aws-ecs-patterns/lib/ecs/application-multiple-target-groups-ecs-service.ts#L149.
All ecs loadbalancer configurations will end up using only the default container name for all target groups.
aws-cdk/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts
Line 513 in 2b6a0be
For example, if i have a task def that has 2 containers, for a SPA. where i have and api and spa server separately.
If you configure multiple target groups:
the result is incorrectly assigning the loadbalancers to the same container:
aws ecs describe-services --cluster ${CLUSTER_NAME} --services web-app
Use Case
The use case is outlined here:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/register-multiple-targetgroups.html#multiple-targetgroups-example3
Proposed Solution
Update ApplicationTargetGroup to include Container name otherwise use the default container name.
aws-cdk/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts
Line 513 in 2b6a0be
this line would then be updated to:
Other Information
No response
Acknowledgements
CDK version used
2.62.1 (build 8641449)
Environment details (OS name and version, etc.)
Ubuntu 22.04.1 LTS
The text was updated successfully, but these errors were encountered: