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.

已提問 2 年前檢視次數 511 次
1 個回答
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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南