-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(ecs-patterns): resolve target group conflict when updating ALB internetFacing or loadBalancerName (under feature flag) #35508
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This review is outdated)
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @puretension, Thank you for your contribution!
As this PR has breaking (destructive) changes, a feature flag will be needed here. See this guide which will help you add a new feature flag for this PR. This fix will then only take effect when the feature flag is set.
Also, see my comment on setting the ID below.
packages/aws-cdk-lib/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts
Outdated
Show resolved
Hide resolved
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the quick edit!
Following steps 4-6 in the feature flag guide, the following is needed:
Add an entry for your feature flag in the README file.
In your tests, ensure that you test your feature with and without the feature flag enabled. You can do this by passing the feature flag to the
context
property when instantiating anApp
.const myFeatureFlag = { [cxapi.MY_FEATURE_FLAG]: true }; const app = new App({ context: myFeatureFlag, }), const stackUnderTest = new Stack(app);In your PR title (which goes into CHANGELOG), add a
(under feature flag)
suffix. e.g:
fix(core): impossible to use the same physical stack name for two stacks (under feature flag)
context: myFeatureFlag,
}),
const stackUnderTest = new Stack(app);
In your PR title (which goes into CHANGELOG), add a (under feature flag) suffix. e.g:
fix(core): impossible to use the same physical stack name for two stacks (under feature flag)
Pull request has been modified.
Thank you for the really quick feedback! I've completed missed steps 4-6. I added the feature flag documentation to the README, implemented tests for both enabled and disabled scenarios following All changes have been committed and pushed. Please let me know if there's anything else needed! |
README.md
Outdated
When enabled, ECS patterns will generate unique target group IDs that include the load balancer name and type (public/private). This prevents CloudFormation conflicts when switching between public and private load balancers. | ||
|
||
Without this flag, switching an ApplicationLoadBalancedFargateService from public to private (or vice versa) fails with "target group cannot be associated with more than one load balancer" error. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong README file to edit. The README file to edit is at packages/aws-cdk-lib/cx-api/README.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abogical Thank you for the correction!
I apologize for the basic mistake of editing the wrong README file.😅
I've now moved the feature flag documentation from the root README.md to the correct location at packages/aws-cdk-lib/cx-api/README.md
as requested.
I'll be more careful to follow the documentation guidelines precisely in future contributions.
Thank you for your patience and guidance!
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integration test snapshot needs to be updated:
CHANGED aws-elasticloadbalancingv2-targets/test/integ.alb-target 3.735s
@aws-cdk-testing/framework-integ: Resources
@aws-cdk-testing/framework-integ: [-] AWS::ElasticLoadBalancingV2::TargetGroup ServiceLBPublicListenerECSGroup0CC8688C destroy
@aws-cdk-testing/framework-integ: [+] AWS::ElasticLoadBalancingV2::TargetGroup ServiceLBPublicListenerECSPrivateGroup93D5832E
@aws-cdk-testing/framework-integ: [~] AWS::ElasticLoadBalancingV2::Listener ServiceLBPublicListener46709EAA
@aws-cdk-testing/framework-integ: └─ [~] DefaultActions
@aws-cdk-testing/framework-integ: └─ @@ -1,7 +1,7 @@
@aws-cdk-testing/framework-integ: [ ] [
@aws-cdk-testing/framework-integ: [ ] {
@aws-cdk-testing/framework-integ: [ ] "TargetGroupArn": {
@aws-cdk-testing/framework-integ: [-] "Ref": "ServiceLBPublicListenerECSGroup0CC8688C"
@aws-cdk-testing/framework-integ: [+] "Ref": "ServiceLBPublicListenerECSPrivateGroup93D5832E"
@aws-cdk-testing/framework-integ: [ ] },
@aws-cdk-testing/framework-integ: [ ] "Type": "forward"
@aws-cdk-testing/framework-integ: [ ] }
@aws-cdk-testing/framework-integ: [~] AWS::ECS::Service Service9571FDD8
@aws-cdk-testing/framework-integ: ├─ [~] LoadBalancers
@aws-cdk-testing/framework-integ: │ └─ @@ -3,7 +3,7 @@
@aws-cdk-testing/framework-integ: │ [ ] "ContainerName": "nginx",
@aws-cdk-testing/framework-integ: │ [ ] "ContainerPort": 80,
@aws-cdk-testing/framework-integ: │ [ ] "TargetGroupArn": {
@aws-cdk-testing/framework-integ: │ [-] "Ref": "ServiceLBPublicListenerECSGroup0CC8688C"
@aws-cdk-testing/framework-integ: │ [+] "Ref": "ServiceLBPublicListenerECSPrivateGroup93D5832E"
@aws-cdk-testing/framework-integ: │ [ ] }
@aws-cdk-testing/framework-integ: │ [ ] }
@aws-cdk-testing/framework-integ: │ [ ] ]
@aws-cdk-testing/framework-integ: └─ [~] DependsOn
@aws-cdk-testing/framework-integ: └─ @@ -1,5 +1,5 @@
@aws-cdk-testing/framework-integ: [ ] [
@aws-cdk-testing/framework-integ: [ ] "ServiceLBPublicListener46709EAA",
@aws-cdk-testing/framework-integ: [-] "ServiceLBPublicListenerECSGroup0CC8688C",
@aws-cdk-testing/framework-integ: [+] "ServiceLBPublicListenerECSPrivateGroup93D5832E",
@aws-cdk-testing/framework-integ: [ ] "TaskTaskRoleE98524A1"
@aws-cdk-testing/framework-integ: [ ] ]
@aws-cdk-testing/framework-integ: [~] AWS::ElasticLoadBalancingV2::TargetGroup NlblistenerTargetsGroupDD2A3CB0
@aws-cdk-testing/framework-integ: └─ [~] DependsOn
@aws-cdk-testing/framework-integ: └─ @@ -1,4 +1,4 @@
@aws-cdk-testing/framework-integ: [ ] [
@aws-cdk-testing/framework-integ: [ ] "ServiceLBPublicListener46709EAA",
@aws-cdk-testing/framework-integ: [-] "ServiceLBPublicListenerECSGroup0CC8688C"
@aws-cdk-testing/framework-integ: [+] "ServiceLBPublicListenerECSPrivateGroup93D5832E"
@aws-cdk-testing/framework-integ: [ ] ]
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet another snapshot to be updated. Unfortunately, there can be a lot of snapshots to update especially modifying this package:
CHANGED aws-ecs-patterns/test/fargate/integ.alb-fargate-service-public-private-switch
Pull request has been modified.
This pull request has been removed from the queue for the following reason: The pull request can't be updated. You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
@Mergifyio update |
❌ Mergify doesn't have permission to updateFor security reasons, Mergify can't update this pull request. Try updating locally. |
@Mergifyio rebase |
✅ Branch has been successfully rebased |
9b7336d
to
e46ee93
Compare
@Abogical Thank you so much for your patience, guidance, and approval throughout this entire contribution process! 🙏 The previous CI Codebuild PR Build failure was likely due to the branch being out of sync🤔. Should I change something more for safely merge? Or is there anything else I need to address before this can be merged? |
@puretension You're welcome!
There seems to be a build issue in our workflow that approves PR's. We're working on this atm. Hopefully, when this is resolved, the PR can be merged. |
@Mergifyio rebase |
…ublic/private Fixes aws#33253
- Add snapshot files for integ.alb-fargate-service-public-private-switch.ts - Includes CloudFormation template showing different target group names - ECS target group for public ALB, ECSPrivate for private ALB
…d-balanced-service-base.ts Co-authored-by: A. Abdel-Rahman <github@abogic.al>
…r feature flag) - Add ECS_PATTERNS_UNIQUE_TARGET_GROUP_ID feature flag - Include loadBalancerName in target group ID when flag is enabled - Prevents CloudFormation conflicts during load balancer replacement - Addresses both internetFacing and loadBalancerName changes Fixes aws#33253 Signed-off-by: puretension <rlrlfhtm5@gmail.com>
Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…tests - Add ECS_PATTERNS_UNIQUE_TARGET_GROUP_ID feature flag documentation to README - Add comprehensive tests for feature flag enabled/disabled/default scenarios - Addresses reviewer feedback for feature flag implementation Signed-off-by: puretension <rlrlfhtm5@gmail.com>
… location Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…naming Updates the integration test snapshot to reflect the new target group naming convention introduced by the feature flag. Private ALB now uses 'ECSPrivate' target group name to prevent CloudFormation conflicts during public/private ALB switching. Signed-off-by: puretension <rlrlfhtm5@gmail.com>
… integration test The integration test for switching between public and private ALB intentionally creates destructive changes to demonstrate the fix for target group conflicts. This is expected behavior when the feature flag is enabled. Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…Destroy Update allowDestroy to use the actual CloudFormation resource names generated by CDK instead of construct IDs. Signed-off-by: puretension <rlrlfhtm5@gmail.com>
- Update allowDestroy list with correct resource IDs - Regenerate snapshots to reflect ECSPrivate target group naming - Fix integration test failures caused by target group name changes Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…GroupId Signed-off-by: puretension <rlrlfhtm5@gmail.com>
✅ Branch has been successfully rebased |
e46ee93
to
cb7df73
Compare
fix(ecs-patterns): resolve target group conflict when switching ALB public/private
Fixes #33253
Issue # (if applicable)
Closes #33253.
Reason for this change
When switching ApplicationLoadBalancedFargateService from public to private (or vice versa), CloudFormation fails with "target group cannot be associated with more than one load balancer" error. This happens because both old and new load balancers try to use the same target group during replacement.
Updating the
loadBalancerName
of ApplicationLoadBalancedFargateService can also trigger the same issue.Description of changes
Modified target group naming in
ApplicationLoadBalancedServiceBase
to include the load balancer type and name. e.g:This ensures each load balancer gets its own target group, preventing conflicts during CloudFormation updates.
This PR contains intentional destructive changes to fix the target group conflict issue:
Target Group Names Changed, e.g:
ECS
(unchanged)ECSPrivate
(new)Impact: When switching from public to private ALB (or vice versa), CloudFormation will:
Justification: This is the intended fix for issue (aws_ecs_patterns): ApplicationLoadBalancedFargateService fails to update when switched from public to private - Fails due to target group #33253. The destructive change is necessary to resolve the CloudFormation conflict.
Breaking Change: ❌ No - This only affects the internal target group naming, not user-facing APIs.
Describe any new or updated permissions being added
No new IAM permissions required.
Description of how you validated changes
integ.alb-fargate-service-public-private-switch.ts
that deploys both public and private ALB servicesChecklist