Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 0.83 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # amazon-ec2 gem
  2. require 'AWS'
  3.  
  4. # Your keys
  5. ACCESS_KEY_ID = 'your AWS ID'
  6. SECRET_ACCESS_KEY = 'your AWS secret'
  7.  
  8. # open EC2 connection
  9. ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
  10.  
  11. # drop in static hosts file for things like localhost
  12. IO.foreach('hosts') {|line| puts line}
  13.  
  14. # Generate the rest
  15. puts "\n\n# Generated by dnsupdate.rb\n"
  16. ec2.describe_instances.reservationSet.item.each do |instance|
  17.   instance.instancesSet.item.first.tagSet.item.each do |tag|
  18.     if tag['key'] == 'dns'
  19.       # EC2 instances are tagged with 'dns' and a hostname as the value
  20.       # I use things like appname_railsenv_app1, etc..
  21.       puts "#{instance.instancesSet.item.first.ipAddress} #{tag['value']}"
  22.       puts "#{instance.instancesSet.item.first.privateIpAddress} #{tag['value']}-int"
  23.     end
  24.   end
  25. end