Last active
August 29, 2015 14:07
Revisions
-
jeremyj revised this gist
Oct 10, 2014 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,9 +17,10 @@ AWS.memoize do snapshots.each do |s| if s.description =~ /Created by CreateImage/ m = s.description.match(/ami\-.{8}/).to_s if images.include?(m) puts "#{m} is a registered AMI" else puts "#{s.id} is a useless snapshot. Deleting..." s.delete end end -
jeremyj created this gist
Oct 10, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/usr/bin/ruby require 'rubygems' require 'aws-sdk' KEY = 'xxx' SEC = 'xxx' REGION = 'eu-west-1' ec2 = AWS::EC2.new(:access_key_id=> KEY, :secret_access_key=> SEC, :region=> REGION) AWS.memoize do snapshots = ec2.snapshots.with_owner(:self) images = ec2.images.with_owner(:self).collect { |i| i.id } snapshots.each do |s| if s.description =~ /Created by CreateImage/ m = s.description.match(/ami\-.{8}/).to_s puts "#{m} is a registered AMI block device" if images.include?(m) unless images.include?(m) puts "#{s.id} is a leftover snapshot. Deleting..." s.delete end end end end