Created
January 31, 2016 18:46
-
-
Save dtenenba/a8cd1efa9747d40fcce3 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# to deregister an ami AND remove its associated snapshot | |
if ARGV.empty? | |
puts "usage: #{$0} <ami-id>" | |
exit | |
end | |
require 'aws-sdk' | |
ec2 = Aws::EC2::Client.new(region: 'us-east-1') | |
ami_id = ARGV.first | |
ami = ec2.describe_images({image_ids: [ami_id], owners: ['self']}) | |
snapshot_id = ami.images.first.block_device_mappings.first.ebs.snapshot_id | |
ec2.deregister_image({dry_run: false, image_id: ami_id}) | |
ec2.delete_snapshot({dry_run: false, snapshot_id: snapshot_id}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment