Skip to content

Instantly share code, notes, and snippets.

@mshock
Last active August 29, 2015 14:05
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 mshock/1e2e7e6aba97a985a5b7 to your computer and use it in GitHub Desktop.
Save mshock/1e2e7e6aba97a985a5b7 to your computer and use it in GitHub Desktop.
Delete all non-running application versions from a specific application in AWS Elastic Beanstalk. (Despite the doc's claim, currently running app versions CAN be deleted so a check is necessary)
#! perl -w
use strict;
use feature 'say';
my $application = $ARGV[0] || 'massdrop-production';
my @app_versions_lines = split /\n/, `/usr/local/bin/aws elasticbeanstalk describe-application-versions --application-name $application`;
my @environment_lines = split /\n/, `/usr/local/bin/aws elasticbeanstalk describe-environments`;
my %running;
for (@environment_lines) {
$running{$1} =1 if /\t(git-\S+)$/;
}
for (@app_versions_lines) {
if (/APPLICATIONVERSIONS\t(\S+)\t.+\t.+\t(\S+)$/ && $1 eq $application && !exists $running{$2}) {
say "deleting $1 - $2";
say `/usr/local/bin/aws elasticbeanstalk delete-application-version --application-name $application --version-label $2`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment