[英]How do you delete an AWS ECS Task Definition?
在 Amazon 的 EC2 Container Service 中创建任务定义后,如何删除或移除它?
It's a known issue .这是一个已知问题。 Once you de-register a Task Definition it goes into INACTIVE state and clutters up the ECS Console.一旦您取消注册任务定义,它就会进入 INACTIVE 状态并使 ECS 控制台变得混乱。
I've recently found this gist (thanks a lot to the creator for sharing!) which will deregister all task definitions for your specific region - maybe you can adapt it to skip some which you want to keep: https://gist.github.com/jen20/e1c25426cc0a4a9b53cbb3560a3f02d1我最近发现了这个要点(非常感谢创建者的分享!)它将取消注册您特定区域的所有任务定义 - 也许您可以对其进行调整以跳过一些您想要保留的内容: https://gist.github .com/jen20/e1c25426cc0a4a9b53cbb3560a3f02d1
You need to have jq to run it: brew install jq
你需要有 jq 才能运行它: brew install jq
I "hard-coded" my region, for me it's eu-central-1
, so be sure to adapt it for your use-case:我“硬编码”了我的区域,对我来说它是eu-central-1
,所以一定要根据你的用例进行调整:
#!/usr/bin/env bash
get_task_definition_arns() {
aws ecs list-task-definitions --region eu-central-1 \
| jq -M -r '.taskDefinitionArns | .[]'
}
delete_task_definition() {
local arn=$1
aws ecs deregister-task-definition \
--region eu-central-1 \
--task-definition "${arn}" > /dev/null
}
for arn in $(get_task_definition_arns)
do
echo "Deregistering ${arn}..."
delete_task_definition "${arn}"
done
Then when I run it, it starts removing them: Deregistering arn:aws:ecs:REGION:YOUR_ACCOUNT_ID:task-definition/NAME:REVISION...
然后当我运行它时,它开始删除它们: Deregistering arn:aws:ecs:REGION:YOUR_ACCOUNT_ID:task-definition/NAME:REVISION...
您可以像以下命令一样取消注册(删除)任务定义: aws ecs deregister-task-definition --task-definition task_defination_name:revision_no
Oneline approach inspired by Anna A reply:灵感来自Anna 的Oneline 方法回复:
aws ecs list-task-definitions --region eu-central-1 \
| jq -M -r '.taskDefinitionArns | .[]' \
| xargs -I {} aws ecs deregister-task-definition \
--region eu-central-1 \
--task-definition {} \
| jq -r '.taskDefinition.taskDefinitionArn'
Created following gist to safely review, filter and deregister AWS task-definitions and revisions in bulk (max 100 at a time) using JS CLI.创建以下要点以使用 JS CLI 安全地审查、过滤和取消注册 AWS 任务定义和修订(一次最多 100 个)。
https://gist.github.com/shivam-nagar/aa79b02b74f616f8714d51e419bd10de https://gist.github.com/shivam-nagar/aa79b02b74f616f8714d51e419bd10de
Can use this to deregister all revisions for task-definition.可以使用它来取消注册任务定义的所有修订。 This will result in task-definition itself marked as inactive.这将导致任务定义本身被标记为非活动状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.