Python CLI utility to help maintain legacy AWS ECS task definitions.
The utility offers the following:
- Set task definitions
ACTIVE
->INACTIVE
that are not associated to ECS tasks. - Mark currently
INACTIVE
task definitions for deletion by ECS.
- Python 3.10+
- Boto3
pip install boto3
Note: adding a --commit
argument will apply changes to ECS task definitions, otherwise all commands are executed in a safe "dry run" mode.
Locate task definitions unused by ECS tasks, set INACTIVE
:
AWS_REGION="ap-southeast-2" \
./cleanup.py --set-inactive
By default --set-inactive
will not mark task definitions INACTIVE
if any version of said definition is in use.
For example:
- Task definition
arn:aws:ecs:REGION:ACCOUNT_ID:task-definition/my-task-definition:123
is currently in use by an ECS task. - Utility locates unused task definition
arn:aws:ecs:REGION:ACCOUNT_ID:task-definition/my-task-definition:666
, but will not markINACTIVE
as there are othermy-task-definition:*
definition versions in use.
In order to set all unused task definition versions INACTIVE
- only leaving in use definition versions ACTIVE
:
AWS_REGION="ap-southeast-2" \
./cleanup.py --set-inactive=aggressive
Mark currently INACTIVE
task definitions for deletion by the ECS subsystem:
AWS_REGION="ap-southeast-2" \
./cleanup.py --delete-inactive
Finally, both operations can be executed together:
AWS_REGION="ap-southeast-2" \
./cleanup.py --set-inactive=aggressive --delete-inactive