Last active
March 8, 2019 16:46
-
-
Save ianblenke/3cb54ef25ddaf4fac410 to your computer and use it in GitHub Desktop.
Delete any ElasticBeanstalk application versions older than a week old that are not currently in use by an environment.
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
awsargs="--profile aws-dev --region us-east-1" | |
now=$(date -j -f "%a %b %d %T %Z %Y" "$(date)" "+%s" 2>/dev/null); | |
oneweekago=$(expr $now - 604800); | |
aws elasticbeanstalk describe-application-versions $awsargs | \ | |
jq -r '.ApplicationVersions[] | .ApplicationName + " " + .VersionLabel + " " + .DateCreated'| \ | |
while read line ; do | |
fields=( $line ) | |
utime=$(date -j -f %Y-%m-%dT%H:%M:%S "${fields[2]};" "+%s" 2>/dev/null); | |
if [[ $utime -lt $oneweekago ]]; then | |
if [ -n "$(aws elasticbeanstalk describe-environments $awsargs \ | |
--application-name ${fields[0]} \ | |
--version-label ${fields[1]}) | \ | |
jq -r '.Environments[]')" ]; then | |
aws elasticbeanstalk delete-application-version $awsargs \ | |
--application-name "${fields[0]}" \ | |
--version-label "${fields[1]}" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eb labs cleanup-versions
now exists