I originally had this script working using the socket module, which is why x is defined the way it is. However, I ended up needing to specify the DNS server being used.
This script is currently running successfully in AWS Lambda, however instead of an FQDN/IP address as an output, I am receiving the output defined at the bottom (which is also coming through in the SNS topic).
I can't seem to find any information about what might be going on here. I am hoping someone can shed some light on how I can fix this.
import boto3
import dns.resolver
import dns.query
my_resolver = dns.resolver.Resolver()
my_resolver.nameservers = ['0.0.0.0'] #IP omitted, but internal DNS server is being used
sns = boto3.client('sns')
a = my_resolver.query('crl.godaddy.com')
x = ('gdcrl.godaddy.com.akadns.net', ['crl.godaddy.com'], ['72.167.18.237'])
def cb_crl_check(event=None, context=None):
crlgodaddy(a, x)
def crlgodaddy(a, x):
if a == x:
pass
else:
response = sns.publish(
TopicArn='arn:aws:sns:xxxxxxxxxxxxxx',
Message=('crl.godaddy.com IP address has changed! \n \nThe old
information was: \n {0} \n \nThe new information is: \n {1}').format(x,a),
Subject = '"crl.godaddy.com IP change"')
if '__name__' == '__main__':
cb_crl_check()
AWS Lambda output:
START RequestId: b637c14d-38f0-46cf-83bf-fd1279aff9d8 Version: $LATEST
***<dns.resolver.Answer object at 0x7fb830c2a450>***
END RequestId: b637c14d-38f0-46cf-83bf-fd1279aff9d8
The answer: I needed to use rrset[0] from the dnspython module in order to get this to work. The following is how the code was changed to make it work:
a = str(my_resolver.query('crl.godaddy.com').rrset[0])
x = '72.167.18.237'