(aws-ecs / aws-elasticloadbalancingv2): CDK resets ALB listener rule actions during stack updates, breaking blue/green deployments
Describe the bug
When using ECS blue/green deployments (either with AlternateTarget for native blue/green or manual weighted target groups), CDK resets the listener rule action to the default state defined in code whenever ANY stack update occurs. This happens even when traffic has been shifted externally via AWS CLI, CodeDeploy, ECS native deployment, or the AWS console.
This makes it very risky to:
- Perform blue/green traffic shifts outside of CDK
- Continue to update infrastructure with CDK without disrupting live traffic routing
Reproduction Steps
Scenario 1: ECS Native Blue/Green with AlternateTarget
Based on the test file packages/aws-cdk-lib/aws-ecs/test/alternate-target-configuration.test.ts:
const prodRule = new elbv2.ApplicationListenerRule(stack, 'ProdRule', {
listener,
priority: 1,
conditions: [elbv2.ListenerCondition.pathPatterns(['/prod'])],
action: elbv2.ListenerAction.forward([blueTargetGroup]), // Hardcoded default
});
const alternateTarget = new ecs.AlternateTarget('GreenTG', {
alternateTargetGroup: greenTargetGroup,
productionListener: ecs.ListenerRuleConfiguration.applicationListenerRule(prodRule),
});
const service = new ecs.FargateService(stack, 'FargateService', {
cluster,
taskDefinition,
});
const target = service.loadBalancerTarget({
containerName: 'web',
containerPort: 80,
alternateTarget,
});
target.attachToApplicationTargetGroup(blueTargetGroup);
Steps to reproduce:
- Deploy the stack - traffic goes to blue
- ECS native blue/green shifts traffic to green (modifies
prodRuleaction) - Update conditions or any other resource in Listener
- Run
cdk deploy - Result: The
prodRuleaction is reset toforward([blueTargetGroup]), breaking live traffic
Scenario 2: Weighted Target Groups
const listenerRule = new elbv2.ApplicationListenerRule(this, 'LiveTrafficRule', {
listener,
priority: 1,
conditions: [elbv2.ListenerCondition.pathPatterns(['/*'])],
action: elbv2.ListenerAction.weightedForward([
{ targetGroup: blue, weight: 100 },
{ targetGroup: green, weight: 0 }
]),
});
Steps to reproduce:
- Deploy with traffic at blue: 100, green: 0
- Use AWS CLI to shift traffic:
aws elbv2 modify-rule --rule-arn <arn> --actions ...(blue: 0, green: 100) - Update ANY other resource in the stack
- Run
cdk deploy - Result: Traffic weights are reset to blue: 100, green: 0 (destroys live traffic routing)
Expected Behavior
CDK should provide a mechanism to exclude listener rule actions from management, similar to:
- Terraform's
lifecycle { ignore_changes = [...] } - CloudFormation's
UpdateReplacePolicyfor specific properties
This would allow:
- CDK to manage the listener rule infrastructure (conditions, priority, target group references)
- External tools (CodeDeploy, ECS, AWS CLI) to manage traffic routing (action/weights)
- Continued CDK updates without resetting traffic state
Current Behavior
CloudFormation always enforces the declarative state defined in CDK code, resetting any external changes to listener rule actions on every stack update.
Possible Solution
Provide one or more of the following:
Option 1: Property-level deletion override
const cfnRule = listenerRule.node.defaultChild as elbv2.CfnListenerRule;
cfnRule.addPropertyDeletionOverride('Actions.0.ForwardConfig.TargetGroups.0.Weight');
cfnRule.addPropertyDeletionOverride('Actions.0.ForwardConfig.TargetGroups.1.Weight');
// or for the entire action
cfnRule.addPropertyDeletionOverride('Actions.0');
Option 2: Dedicated property to exclude action from management
const listenerRule = new elbv2.ApplicationListenerRule(this, 'Rule', {
listener,
conditions: [...],
action: elbv2.ListenerAction.forward([blueTargetGroup]),
manageAction: false, // Don't update the action after initial creation
});
Option 3: Import pattern for external management
const listenerRule = elbv2.ApplicationListenerRule.fromListenerRuleArn(
this,
'ExistingRule',
ruleArn,
{ manageAction: false }
);
Environment
- CDK CLI Version: 2.x
- Framework Version: aws-cdk-lib 2.x
- Node.js Version: 18.x+
- OS: All
- Language: TypeScript/JavaScript
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
Current Behavior
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.233.0
AWS CDK CLI version
2.1033.0
Node.js Version
v24.5.0
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response
Hi @adriantaut,
Thanks for this detailed bug report! This is a good catch - you've identified a real pain point when using CDK with ECS Native blue/green deployments.
Root Cause Analysis:
The issue stems from a design gap between ECS Native B/G and CloudFormation's declarative model:
-
When you configure ECS Native B/G with
AlternateTarget, CDK passes theProductionListenerRuleARN to ECS viaAdvancedConfiguration— this tells ECS which listener rule to modify during traffic shifts. -
However, the listener rule itself (with its
Actionsproperty including target group weights) is still fully managed by CloudFormation. -
When ECS shifts traffic, it modifies the listener rule's
Actionsdirectly via the ELBv2 API. CloudFormation is unaware of this change. -
On the next stack update, CloudFormation sees "drift" and resets the
Actionsto match the template — breaking your live traffic routing.
This appears to be a gap in the ECS Native B/G + CloudFormation integration. The AWS documentation shows how to set up ECS Native B/G with CloudFormation, but doesn't address ongoing stack updates after ECS has shifted traffic.
I have navigated all public docs but didn't found anything about this.
Actions:
This issue highlights a gap in the ECS Native B/G + IaC story. We'll:
-
Reach out to the ECS/CloudFormation teams to understand if there's a recommended pattern for this scenario, or if this is a known limitation.
-
Update documentation to clarify the interaction between ECS Native B/G and CloudFormation stack updates.
Related Issues:
- #36012 - ECS CODE_DEPLOY migration issues (related but different root cause)
ASCII notes
┌─────────────────────────────────────────────────────────────────────────────┐
│ TWO DIFFERENT B/G APPROACHES │
└─────────────────────────────────────────────────────────────────────────────┘
APPROACH 1: CloudFormation + CodeDeploy B/G (Transform-based)
─────────────────────────────────────────────────────────────
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CloudFormation│────▶│ CodeDeploy │────▶│ Traffic Shift│
│ (orchestrates)│ │ (executes) │ │ (managed) │
└──────────────┘ └──────────────┘ └──────────────┘
│
└──► CFN KNOWS about traffic state ✓
└──► No drift issue ✓
APPROACH 2: ECS Native B/G (AlternateTarget) ◄── Issue #36649
─────────────────────────────────────────────
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CloudFormation│ │ ECS │────▶│ Traffic Shift│
│ (infra only) │ │ (deploys) │ │ (via AWS API)│
└──────────────┘ └──────────────┘ └──────────────┘
│ │
│ └──► Modifies listener rules directly
│
└──► CFN DOESN'T KNOW about traffic state ✗
└──► Drift/reset issue on next deploy ✗
related PRs #35061
Any strategies to mitigate the drift ? Would it be possible to add an action like "bluegreen" and just act as a placeholder that is ignored at synth time ?
Any news on this ? The issue has been opened since January. It's almost May
just had another Production incident because of this...are there any news? Thank you and would highly appreciate a fix!
We also got bitten by this bug when spiking native blue/green Fargate deployments. We ended up working around this by managing listener rules outside of IaC, but native CDK support would be ideal 🙏
@pahud Is there any update on this matter? A workaround would also be much appreciated.