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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠