Created
March 31, 2014 04:58
-
-
Save arukoh/9885565 to your computer and use it in GitHub Desktop.
自分のAMI一覧を表示するスクリプト。
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
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