How do you delete an AWS ECS Task Definition?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amazon Elastic Container Service (ECS) is a fully managed container orchestration service that facilitates deploying, managing, and scaling containerized applications using Docker. One of the essential components in Amazon ECS is the task definition. It specifies parameters for Docker containers, such as which image to use, CPU and memory requirements, and network configurations. Over time, it's common to have several versions of a task definition, which could clutter your environment. Therefore, knowing how to delete an AWS ECS Task Definition that is no longer needed is crucial for maintaining a clean and efficient infrastructure.
What is a Task Definition?
A task definition in AWS ECS acts as a blueprint for your application. It includes:
- Container Definitions: Details about the Docker containers, including image name, required CPU and memory, networking information, and storage requirements.
- Volumes: Persistent data storage configurations.
- Networking: Details on how containers should be networked.
- IAM Roles: Permissions required for the containers to execute their tasks.
When you create a new version of a task definition, the older versions are often retained unless explicitly deleted, as task definitions are immutable and versioned.
Why Delete Task Definitions?
Managing task definitions efficiently is necessary for:
- Cost Management: Inactive but retained resources can lead to unnecessary costs.
- Resource Efficiency: Removing obsolete task definitions clears storage and simplifies environment management.
- Cleaner Environment: It helps in maintaining organized and clutter-free AWS accounts.
Preconditions
Before deleting a task definition:
- Ensure that no running tasks use the version of the task definition you plan to delete.
- Verify you have the necessary permissions (e.g.,
ecs:DeregisterTaskDefinition).
How to Delete an AWS ECS Task Definition
AWS allows you to delete task definitions using either the AWS Management Console, the AWS CLI, or an SDK (e.g., Boto3 for Python). Below is a detailed guide for each method.
Using AWS Management Console
- Navigate to ECS Dashboard: Open the AWS Management Console and navigate to the ECS service.
- Select Task Definitions: On the left panel, select "Task Definitions." This will list all task definitions available in your account.
- Choose Task Definition: Find the task definition you want to delete. You can search by family name or filter by status.
- Deregister Version: Click on the specific version of the task definition you wish to delete. Click on "Actions" and choose "Deregister Task Definition."
- Confirmation: A confirmation dialog appears. Confirm the deregistration to delete that version.
Using AWS CLI
You can also delete a task definition using the AWS Command Line Interface.
- List Task Definitions: To view your task definitions, use:
- Deregister a Task Definition: Use the following command to deregister a task definition:
Replace <task-definition-arn> with the full ARN of the task definition you want to delete.
Using AWS SDK (Boto3 for Python)
For those using programming languages, the SDK provides a way to manage AWS resources, including ECS task definitions.
- Initialize the Boto3 Client:
- Deregister Task Definition:
Important Notes
- Deregistering vs. Deleting: The term "delete" is not commonly used for task definitions in ECS. Task definitions are "deregistered" and though they remain in the ECS list, they become inactive and can't be used to run new tasks.
- Immutable Nature: Once a task definition is deregistered, you cannot revoke it. A new version or an entirely new task definition must be created for any further changes.
Summary Table
Below is a table summarizing the methods to delete a task definition:
| Method | Command/Steps | Notes |
| AWS Management Console | Task Definitions ➔ Select Version ➔ Action ➔ Deregister | Simple UI-based method suitable for manual management. |
| AWS CLI | aws ecs deregister-task-definition ... | Fast, scriptable, suitable for automation and large environments. |
| AWS SDK (Boto3) | boto3.client('ecs').deregister_task_definition(...) | Ideal for integration into applications or scripts with error handling and automation built-in. |
Conclusion
Keeping your AWS ECS task definitions clean and up to date is vital for optimal resource management and security. While task definitions are immutable and versioned, the ability to deregister unused versions ensures a seamless and cost-effective container orchestration service. By leveraging the AWS Console, CLI, or SDKs, administrators can efficiently maintain the lifecycle of their container applications.
Related reading
- How do you delete an AWS EMR Cluster?
- How do you full text search an Amazon S3 bucket?
- How do you get kubectl to log in to an AWS EKS cluster?
- How do you install modules within sagemaker training jobs?
- How do you locally load model.tar.gz file from Sagemaker?
- How do you look at console.log output of the amazon lambda function
- How do you make an S3 object public via the aws Java SDK?
- How do you pass Authorization header through API Gateway to HTTP endpoint?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.