I manage a project which uses AWS CDK. All Fargate services in this project can be accessed through two load balancers. Each service thus lives in two target groups - one for each load balancer.
I need to remove one of the load balancers. The first step for this is to remove the add_targets
from the load balancer listeners created by CDK :
httpslistener.add_targets(
service_name + "_target",
target_group_name=service_name + "-https",
targets=[
target.load_balancer_target(
container_name=service_name,
container_port=service_list[s]["port"],
)
],
conditions=[
elbv2.ListenerCondition.host_headers(
sorted(service_list[s]["domains"])
)
],
priority=service_list[s]["priority"],
port=80,
[...]
)
When I attempt to update the relevant CDK stack, it fails with the following message :
Export test-service-stack:ExportsOutputRefalbhttpslistener[servicename]targetGroup805DF3FB5647F5C5 cannot be deleted as it is in use by test-servicestack[servicename]24F3888E
There is no explicity dependency by any service on the target groups set up in the CDK stack. The above piece of clode is the "nearest" I get when it comes to manage the target group. No matter what I try, it fails with the above message.
How can I resolve this issue with AWS CDK? Right now, I am unable to remove the redundant load balancer. I'd rather not make changes directly in the AWS console, as this most likely will result in conflicts with the AWS CDK state.