Skip to content

Instantly share code, notes, and snippets.

@wolfg1969
Created December 4, 2015 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfg1969/d38e495a6844a0798986 to your computer and use it in GitHub Desktop.
Save wolfg1969/d38e495a6844a0798986 to your computer and use it in GitHub Desktop.
Delete obsolete elasticbeanstalk app versions
#!/usr/bin/env bash
# 2015/12/03 Guo Yong
# Delete obsolete elasticbeanstalk app versions
# http://franklanganke.com/remove-old-aws-elastic-beanstalk-application-versions-bash-cron/
application=$1
filter="uat"
aws elasticbeanstalk describe-environments --application-name=$application --output text --query 'Environments[*].[EnvironmentName,VersionLabel]' | grep -i $filter | awk '{print $2}' > deployed-versions.txt
versions=$(aws elasticbeanstalk describe-application-versions --application-name $application --output text --query 'ApplicationVersions[*].[VersionLabel,Description]' | grep $filter | awk '{print $1}')
for version in $versions
do
if grep -Fxq "$version" deployed-versions.txt
then
echo "Version \"$version\" is deployed. Skipping......"
else
aws elasticbeanstalk delete-application-version --application-name $application --version-label $version --delete-source-bundle && echo "Version \"$version\" is deleted." || echo "Failed to delete version \"$verion\""
fi
done
rm -f deployed-versions.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment