Skip to content

Instantly share code, notes, and snippets.

@elawad
Last active March 13, 2022 22:12
Show Gist options
  • Save elawad/9b7dbefa8492dd6f2fc8d2d8ad47c829 to your computer and use it in GitHub Desktop.
Save elawad/9b7dbefa8492dd6f2fc8d2d8ad47c829 to your computer and use it in GitHub Desktop.
Deregister ECS Task Definitions by family and revision range
#!/bin/bash
FAMILY=your-task-def-family-name
# Update ranges to deregister certain revisions.
for VER in {1..100}; do
# Sleep after 40 calls to reduce AWS ThrottlingException.
if (( $VER % 41 == 0 )); then
sleep 10
fi
TASK_DEF=$FAMILY:$VER
# Capture errors and supress logs.
ERR=$(
aws ecs deregister-task-definition --task-definition $TASK_DEF 2>&1 > /dev/null
)
# If a ThrottlingException occurred, sleep and retry.
if [[ $ERR == *"ThrottlingException"* ]]; then
sleep 10
aws ecs deregister-task-definition --task-definition $TASK_DEF 2>&1 > /dev/null
fi
echo "$TASK_DEF - deregistered"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment