Created
April 3, 2015 08:33
-
-
Save yuta-imai/c562e8bb4ae076fc9c6f to your computer and use it in GitHub Desktop.
最新のAmazon Linux AMIのIDを取得する ref: http://qiita.com/imaifactory/items/35acd4b8b9f96f7d712b
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 characters
| #!/usr/bin/env ruby | |
| require 'aws-sdk-core' | |
| ec2 = Aws::EC2::Client.new(region:'ap-northeast-1') | |
| images = ec2.describe_images( | |
| owners: ['amazon'], | |
| filters: [ | |
| { | |
| name:"architecture", | |
| values:["x86_64"] | |
| }, | |
| { | |
| name:"hypervisor", | |
| values:["xen"] | |
| } | |
| ] | |
| ) | |
| latest_ami = images[:images].find_all{|image| | |
| image[:description] | |
| }.find_all{|image| | |
| image[:description].match(/Amazon Linux/) | |
| }.find_all{|image| | |
| image[:description].match(/EBS/) | |
| }.find_all{|image| | |
| image[:description].match(/HVM/) | |
| }.sort_by{|image| | |
| image[:creation_date] | |
| }.reverse.first | |
| puts latest_ami[:image_id] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment