Created
January 12, 2018 15:33
-
-
Save smallfield/474e59f414e2ebdc6a2d752ff4d2b777 to your computer and use it in GitHub Desktop.
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
require "net/http" | |
require "uri" | |
require "aws-sdk" | |
target_domain=ARGV[0] | |
zone_name=target_domain.split(".")[-2, 2].join(".") + "." | |
# Get global IP address | |
uri = URI.parse("https://ifconfig.co/ip") | |
ipaddr = Net::HTTP.get_response(uri).body.strip | |
client = Aws::Route53::Client.new | |
zone = client.list_hosted_zones.hosted_zones.find{|z| z.name == zone_name} | |
resp = client.change_resource_record_sets({ | |
change_batch: { | |
changes: [ | |
{ | |
action: "UPSERT", | |
resource_record_set: { | |
name: TARGET_DOMAIN, | |
resource_records: [ | |
{ | |
value: ipaddr, | |
}, | |
], | |
ttl: 60, | |
type: "A", | |
}, | |
}, | |
], | |
}, | |
hosted_zone_id: zone.id, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment