Created
November 8, 2012 17:59
-
-
Save bartimaeus/4040420 to your computer and use it in GitHub Desktop.
Updated Route53 Record When EC2 Instance Starts
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 |
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
#!/bin/bash | |
su - ubuntu -c "ruby $HOME/bin/update-dns.rb" | |
# file location: /etc/init.d/update-dns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
/etc/init.d/update-dns
when EC2 instance boots withsudo update-rc.d update-dns defaults