Created
November 13, 2012 06:45
-
-
Save bartimaeus/4064360 to your computer and use it in GitHub Desktop.
Script to Update Route53 with an EC2 Instance IP Address
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
# /home/ubuntu/bin/update-dns.rb | |
require 'rubygems' | |
require 'open-uri' | |
require 'route53' | |
zone = "bartimae.us" | |
record_type = "A" | |
ip_address = open("http://169.254.169.254/latest/meta-data/public-ipv4") { |f| f.read } | |
begin | |
conn = Route53::Connection.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']) | |
conn.get_zones(zone).first.get_records(record_type).each {|record| record.update(record.name, record.type, record.ttl, [ip_address])} | |
puts "DNS Updated for #{zone}" | |
rescue RuntimeError | |
puts "Error accessing Route53 with supplied credentials" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment