Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Created April 3, 2015 08:33
Show Gist options
  • Select an option

  • Save yuta-imai/c562e8bb4ae076fc9c6f to your computer and use it in GitHub Desktop.

Select an option

Save yuta-imai/c562e8bb4ae076fc9c6f to your computer and use it in GitHub Desktop.
最新のAmazon Linux AMIのIDを取得する ref: http://qiita.com/imaifactory/items/35acd4b8b9f96f7d712b
#!/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