Skip to content

Python CLI utility to help maintain legacy AWS ECS task definitions in bulk.

License

Notifications You must be signed in to change notification settings

magnetikonline/aws-ecs-task-definition-cleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS ECS task definition cleanup

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.

Requirements

  • Python 3.10+
  • Boto3
     pip install boto3

Usage

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 mark INACTIVE as there are other my-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

Reference

About

Python CLI utility to help maintain legacy AWS ECS task definitions in bulk.

Topics

Resources

License

Stars

Watchers

Forks

Languages