Skip to content

Instantly share code, notes, and snippets.

@murarisumit
Last active November 17, 2020 00:06
Show Gist options
  • Save murarisumit/700499c24169adef7574 to your computer and use it in GitHub Desktop.
Save murarisumit/700499c24169adef7574 to your computer and use it in GitHub Desktop.
Check if DNS record exist in route53 #boto #aws #route53
def checkifDnsRecordExist(domain_name,dns_record):
'''
(str, str) --> (str)
Read your domain-name and dns_record and check if it exists or not
Returns recordSet and it's value in return
#If record exist
>>> checkifDnsRecordExist("domain_name.com", "mail.domain_name.com")
mail.domain_name.com : 5.3.5.3
#If record doesn't exist
>>> checkifDnsRecordExist("domain_name.com", "mail.domain_name.com")
0
'''
r53conn = boto.connect_route53(aws_access_key_id="xxxxxxxxxxxxxx",aws_secret_access_key="yyyyyyyyyy")
recordSets = r53conn.get_zone(domain_name)
for recordset in recordSets.get_records():
if recordset.name == dns_record+".":
return recordset.name + " : " + recordset.to_print()
return 0
checkifDnsRecordExist("domain_name.com", "mail.domain_name.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment