-
Notifications
You must be signed in to change notification settings - Fork 4k
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
ecs: unable to change networkMode back to the default #33410
Comments
This appears to be an issue with how CDK handles the removal of load balancer target groups from ECS services. When you try to remove the ALB configuration, the service is still trying to reference the old target group during the CloudFormation update. To resolve this, I recommend:
const realtimeWsService = new ecs.Ec2Service(this, 'Service', {
serviceName: 'Service',
cluster: props.cluster,
taskDefinition,
capacityProviderStrategies: [gpucapacityProviderStrategy],
// Keep the networkMode: AWS_VPC for now
serviceConnectConfiguration: {
// ... rest of the config
}
});
// Remove all load balancer related code
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef', {
family: 'task-def',
taskRole: taskRole,
// Now you can remove networkMode
}); This two-step approach should allow CloudFormation to properly handle the removal of the load balancer configuration before changing the network mode. While one-step deployment is preferable, based on my analysis of the CDK codebase and the issue, I don't recommend trying to do this in one step. Here's why:
Therefore, while it might be tempting to do this in one step, it's safer and more reliable to:
This follows AWS's best practices for service updates and ensures a clean, predictable deployment process. Attempting to do both changes at once could lead to deployment failures or service disruption. Let me know if it works for you. |
I tested that approach as well but it also failed:
I consider CDK as a declarative language that describes an expected state, so I still see this as a bug. |
Describe the bug
An EcsService defined like this:
This deploys and works perfectly fine. However, now, I want to change the approach and I want to remove the public ALB altogether and go back to the default
networkMode
.This bails out with:
If you check the synchronised template, you'll see it is still referencing the TargetGroup, even though it's nowhere in the code.
Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
above
Current Behavior
above
Reproduction Steps
above
Possible Solution
No response
Additional Information/Context
CDK CLI Version
2.177.0 (build b396961)
Framework Version
No response
Node.js Version
v22.12.0
OS
MacOS
Language
TypeScript
Language Version
Other information
No response
The text was updated successfully, but these errors were encountered: