Skip to content

Instantly share code, notes, and snippets.

@arukoh
Created March 31, 2014 04:58
Show Gist options
  • Save arukoh/9885565 to your computer and use it in GitHub Desktop.
Save arukoh/9885565 to your computer and use it in GitHub Desktop.
自分のAMI一覧を表示するスクリプト。
require "aws-sdk"
ACCOUNT_NUMBER = ENV['ACCOUNT_NUMBER'}
REGION_NAME = ENV['REGION_NAME']
AMI_DESCRIPTION = ENV['AMI_DESCRIPTION_FILTER']
ec2 = AWS::EC2.new(region: REGION_NAME)
images = ec2.images.filter('owner-id', ACCOUNT_NUMBER).filter('description', AMI_DESCRIPTION)
sorted = images.to_a.sort{|a, b| b.description <=> a.description }
sorted.each do |image|
output = []
output << image.id
output << image.state
output << image.description
output << image.block_device_mappings.map{|device, hash| hash[:snapshot_id] }.join(',')
puts output.join("\t")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment