gpt4 book ai didi

amazon-web-services - Cloudformation 中删除 ECS 服务失败

转载 作者:行者123 更新时间:2023-12-03 07:11:30 25 4
gpt4 key购买 nike

我在删除包含 ECS 集群和 ECS 服务的 Cloudformation 堆栈时遇到了一个小问题。

如果我只是从 CF 控制台手动删除它,则会出现删除失败并出现以下错误:

AWS::ECS::Cluster The Cluster cannot be deleted while Container Instances are active or draining.

根据 AWS 文档 ( https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CleaningUp.html ),我们编写了一个脚本来使用 AWS cli 删除集群,该脚本在周五之前几个月一直运行良好。

stack=$1
services="$(aws ecs list-services --cluster "$stack" | grep "$stack" | sed -e 's/"//g' -e 's/,//')"
for service in $services; do
aws ecs update-service --cluster "$stack" --service "$service" --desired-count 0
aws ecs delete-service --cluster "$stack" --service "$service"
done

for id in $(aws ecs list-container-instances --cluster "$stack" | grep container-instance | sed -e 's/"//g' -e 's/,//'); do
aws ecs deregister-container-instance --cluster "$stack" --container-instance "$id" --force
done

for service in $services; do
aws ecs wait services-inactive --cluster "$stack" --services "$service"
done

aws ecs delete-cluster --cluster "$stack"
aws cloudformation delete-stack --stack-name "$stack"

但是我们现在收到这个新错误:

AWS::ECS::Service: Service was not ACTIVE. (Service: AmazonECS; Status Code: 400; Error Code: ClientException; Request ID: xxxx-xxxx-xxxx-xxxx)

因此,我删除了 ECS 更新和删除服务调用,认为它们可能只需要保持事件状态,当我们删除 ECS 集群时,它会处理它们。但是当我这样做时,我收到了这个相互矛盾的错误:

AWS::ECS::Cluster The Cluster cannot be deleted while Services are active. (Service: AmazonECS; Status Code: 400; Error Code: ClusterContainsServicesException)

我认为我只是做错了一些事情,所以任何见解将不胜感激。

最佳答案

我已经为此绞尽脑汁很长时间了,直到上周才找到可行的解决方案。 AWS 刚刚发布了新的 API,其中有--force 选项用于删除服务。此任务和服务现在已损坏,唯一的处理方法是删除它,您无法再更新它。

您现在可以使用此命令删除您的服务;上周这是不可能的!{code}aws ecs delete-service --service my-http-service --force true{code}

希望这有帮助

关于amazon-web-services - Cloudformation 中删除 ECS 服务失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50914723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com