Skip to content

Instantly share code, notes, and snippets.

@smallfield
Created January 12, 2018 15:33
Show Gist options
  • Save smallfield/474e59f414e2ebdc6a2d752ff4d2b777 to your computer and use it in GitHub Desktop.
Save smallfield/474e59f414e2ebdc6a2d752ff4d2b777 to your computer and use it in GitHub Desktop.
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