AWS CDK : How can I remove an AWS target group which a FargateService depends on?

0

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.

asked 2 years ago502 views
1 Answer
0

Hello,

This could be achieved by using the UpdateService API call. You can view the following doc for more information:

https://aws.amazon.com/about-aws/whats-new/2022/03/amazon-ecs-service-api-updating-elastic-load-balancers-service-registries-tag-propagation-ecs-managed-tags/

You can try to update the ECS service using CDK with the parameters defined in the above document.

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions