Last active
March 13, 2022 22:12
-
-
Save elawad/9b7dbefa8492dd6f2fc8d2d8ad47c829 to your computer and use it in GitHub Desktop.
Deregister ECS Task Definitions by family and revision range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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