Skip to content

Instantly share code, notes, and snippets.

@bartimaeus
Created November 13, 2012 06:45
Show Gist options
  • Save bartimaeus/4064360 to your computer and use it in GitHub Desktop.
Save bartimaeus/4064360 to your computer and use it in GitHub Desktop.
Script to Update Route53 with an EC2 Instance IP Address
# /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