Reputation: 2167
Once you've created a task definition in Amazon's EC2 Container Service, how do you delete or remove it?
Upvotes: 105
Views: 53846
Reputation: 701
Upvotes: 1
Reputation: 25659
The DeleteTaskDefinitions API closes the issue noted in the accepted answer. As previously, deregistering a task definition sets it as inactive. The new API allows you to delete INACTIVE
task definitions:
aws ecs delete-task-definitions --task-definitions family:revision
aws ecs delete-task-definitions --task-definitions myInactiveTaskDef:1 myInactiveTaskDef:2 myInactiveTaskDef:3
Upvotes: 15
Reputation: 1282
There is no option to delete a task definition on the AWS console.
But, you can deregister (delete) a task definition by executing the following command number of revisions that you have:
aws ecs deregister-task-definition --task-definition task_defination_name:revision_no
Upvotes: 8
Reputation: 8828
Now its supported I just went inside the Task Definations and clicked on Actions and click on Deregister and it was removed from the UI
Upvotes: 2
Reputation: 1494
It's a known issue. Once you de-register a Task Definition it goes into INACTIVE state and clutters up the ECS Console.
If you want to vote for it to be fixed, there is an issue on Github. Simply give it a thumbs up, and it will raise the priority of the request.
Upvotes: 127
Reputation: 154
Created following gist to safely review, filter and deregister AWS task-definitions and revisions in bulk (max 100 at a time) using JS CLI.
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.
Upvotes: 1
Reputation: 318
Oneline approach inspired by Anna A reply:
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'
Upvotes: 7
Reputation: 1758
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
You need to have jq to run it:
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:
#!/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...
Upvotes: 17