Skip to content

Instantly share code, notes, and snippets.

@jpwynn
Last active May 6, 2022 21:47
Show Gist options
  • Save jpwynn/fbe34669ce5e6a41f7b6694c7fd1edf1 to your computer and use it in GitHub Desktop.
Save jpwynn/fbe34669ce5e6a41f7b6694c7fd1edf1 to your computer and use it in GitHub Desktop.
a quick ruby script to update route53 contacts for all registered domains, since R53 dashboard STILL offers no way to do that
# assumes gem is installed for current ruby version:
# gem install aws-sdk-route53domains
# assumes you have already setup a named-profile YOUR_PROFILE_NAME for an aws cli credential with sufficient access
# to your route53 to list and update domain registration records
# an IAM user with AmazonRoute53FullAccess is overkill, dangerous, but easiest
# ======
require 'aws-sdk-route53domains'
local_aws_profile_name = 'YOUR_PROFILE_NAME'
client = Aws::Route53Domains::Client.new(profile: local_aws_profile_name)
domains_obj = client.list_domains(max_items: 100)
domains_list_obj = domains_obj.domains
my_domains = []
domains_list_obj.each do |dobj|
my_domains << dobj["domain_name"]
end
# only need the fields that changed, full format fields comments are below for reference
# (you could of course have a diff hash for each of the 3 types of contacts)
contact_hash = {address_line_1: "MY NEW ADDRESS 1", address_line_2: "MY NEW ADDRESS 2", city: "MY NEW CITY", zip_code: "MY NEWZIP"}
op_ids = []
missed = []
dupes = []
other_errors = []
my_domains.each do |this_domain|
puts
puts "submitting #{this_domain}..."
begin
resp = client.update_domain_contact(
domain_name: this_domain,
admin_contact: contact_hash,
registrant_contact: contact_hash,
tech_contact: contact_hash )
puts "response: #{resp.inspect}"
op_ids << {domain: this_domain, op_id: resp["operation_id"]}
rescue StandardError => e
if e.message.downcase.include?("rate exceeded")
puts "#{this_domain} rate exceeded, run again"
missed << this_domain
elsif e.message.downcase.include?("request already pending")
puts "#{this_domain}: ignoring error... duplicate"
dupes << this_domain
else
puts "#{this_domain}: Exception: #{e.message}"
other_errors << {domain: this_domain, error: e.message }
end
end
sleep 5
end
puts "#{dupes.count} dupes already submitted, earlier changes still pending"
puts "#{missed.count} missed (rate exceeded), retry later: #{missed}"
puts "#{other_errors.count} OTHER errors: #{other_errors}"
puts "if you want to check back programatically on status of updates, the ops ids for each domain are in op_ids[]"
# aws SDK's complete contact hash format is:
# admin_contact: {
# first_name: "ContactName",
# last_name: "ContactName",
# contact_type: "PERSON", # accepts PERSON, COMPANY, ASSOCIATION, PUBLIC_BODY, RESELLER
# organization_name: "ContactName",
# address_line_1: "AddressLine",
# address_line_2: "AddressLine",
# city: "City",
# state: "State",
# country_code: "AC", # accepts AC, AD, AE, AF, AG, AI, AL, AM, AN, AO, AQ, AR, AS, AT, AU, AW, AX, AZ, BA, BB, BD, BE, BF, BG, BH, BI, BJ, BL, BM, BN, BO, BQ, BR, BS, BT, BV, BW, BY, BZ, CA, CC, CD, CF, CG, CH, CI, CK, CL, CM, CN, CO, CR, CU, CV, CW, CX, CY, CZ, DE, DJ, DK, DM, DO, DZ, EC, EE, EG, EH, ER, ES, ET, FI, FJ, FK, FM, FO, FR, GA, GB, GD, GE, GF, GG, GH, GI, GL, GM, GN, GP, GQ, GR, GS, GT, GU, GW, GY, HK, HM, HN, HR, HT, HU, ID, IE, IL, IM, IN, IO, IQ, IR, IS, IT, JE, JM, JO, JP, KE, KG, KH, KI, KM, KN, KP, KR, KW, KY, KZ, LA, LB, LC, LI, LK, LR, LS, LT, LU, LV, LY, MA, MC, MD, ME, MF, MG, MH, MK, ML, MM, MN, MO, MP, MQ, MR, MS, MT, MU, MV, MW, MX, MY, MZ, NA, NC, NE, NF, NG, NI, NL, NO, NP, NR, NU, NZ, OM, PA, PE, PF, PG, PH, PK, PL, PM, PN, PR, PS, PT, PW, PY, QA, RE, RO, RS, RU, RW, SA, SB, SC, SD, SE, SG, SH, SI, SJ, SK, SL, SM, SN, SO, SR, SS, ST, SV, SX, SY, SZ, TC, TD, TF, TG, TH, TJ, TK, TL, TM, TN, TO, TP, TR, TT, TV, TW, TZ, UA, UG, US, UY, UZ, VA, VC, VE, VG, VI, VN, VU, WF, WS, YE, YT, ZA, ZM, ZW
# zip_code: "ZipCode",
# phone_number: "ContactNumber",
# email: "Email",
# fax: "ContactNumber",
# extra_params: [
# {
# name: "DUNS_NUMBER", # required, accepts DUNS_NUMBER, BRAND_NUMBER, BIRTH_DEPARTMENT, BIRTH_DATE_IN_YYYY_MM_DD, BIRTH_COUNTRY, BIRTH_CITY, DOCUMENT_NUMBER, AU_ID_NUMBER, AU_ID_TYPE, CA_LEGAL_TYPE, CA_BUSINESS_ENTITY_TYPE, CA_LEGAL_REPRESENTATIVE, CA_LEGAL_REPRESENTATIVE_CAPACITY, ES_IDENTIFICATION, ES_IDENTIFICATION_TYPE, ES_LEGAL_FORM, FI_BUSINESS_NUMBER, FI_ID_NUMBER, FI_NATIONALITY, FI_ORGANIZATION_TYPE, IT_NATIONALITY, IT_PIN, IT_REGISTRANT_ENTITY_TYPE, RU_PASSPORT_DATA, SE_ID_NUMBER, SG_ID_NUMBER, VAT_NUMBER, UK_CONTACT_TYPE, UK_COMPANY_NUMBER, EU_COUNTRY_OF_CITIZENSHIP
# value: "ExtraParamValue", # required
# },
# ],
# },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment