diff --git a/code/ddns-lambda.py b/code/ddns-lambda.py index c43675b..a70cc45 100755 --- a/code/ddns-lambda.py +++ b/code/ddns-lambda.py @@ -39,7 +39,7 @@ LOGGER = logging.getLogger() ACCOUNT = None REGION = None -VERSION = '0.0.2' +VERSION = '0.0.3' # Adjust the logging level [logging.INFO, logging.DEBUG, logging.WARNING, etc] LOGGER.setLevel(logging.DEBUG) @@ -51,6 +51,8 @@ TAGKEY_CNAME = os.environ['TagKeyCname'] TAGKEY_ZONE = os.environ['TagKeyZone'] TAGKEY_HOSTNAME = os.environ['TagKeyHostName'] +DNS_RR_TTL = int(os.environ['DNS_RR_TimeToLive']) +DNS_RR_TTL = 60 if DNS_RR_TTL==0 else DNS_RR_TTL print('Loading function v%s: %s'.format(VERSION,datetime.datetime.now().time().isoformat())) @@ -153,7 +155,7 @@ def lambda_handler( # Only doing something if the state is running if state == 'running': - LOGGER.debug("sleeping for 60 seconds %s", lineno()) + LOGGER.debug("sleeping for {} seconds {}".format(SLEEPTIME,lineno())) if "pytest" in sys.modules: # called from within a test run @@ -381,6 +383,7 @@ def lambda_handler( private_hosted_zone_properties = get_hosted_zone_properties(route53, private_hosted_zone_id) LOGGER.debug("private_hosted_zone_properties:" " %s", str(private_hosted_zone_properties) + lineno()) + fqdn = private_host_name + '.' + private_hosted_zone_name if state == 'running': found_vpc_id = False if 'VPCs' in private_hosted_zone_properties: @@ -425,7 +428,8 @@ def lambda_handler( reversed_ip_address, 'in-addr.arpa', 'PTR', - private_dns_name + fqdn +# private_dns_name ) caller_response.append('Created PTR record in zone id: ' + @@ -433,7 +437,8 @@ def lambda_handler( ' for hosted zone ' + str(reversed_ip_address) + 'in-addr.arpa with value: ' + - str(private_dns_name)) + str(fqdn)) +# str(private_dns_name)) except BaseException as err: LOGGER.debug("%s", str(err)+lineno()) @@ -462,7 +467,8 @@ def lambda_handler( reversed_ip_address, 'in-addr.arpa', 'PTR', - private_dns_name + fqdn +# private_dns_name ) caller_response.append('Deleted PTR record in zone id: ' + @@ -471,7 +477,8 @@ def lambda_handler( str(reversed_ip_address) + '.' + str(private_dns_name) + ' with value: ' + - str(private_dns_name)) + str(fqdn)) +# str(private_dns_name)) except BaseException as err: LOGGER.debug("%s", str(err)+lineno()) @@ -725,6 +732,7 @@ def lambda_handler( " %s", str(private_hosted_zone_properties) + lineno()) # create A records and PTR records + fqdn = private_host_name + '.' + private_hosted_zone_name if state == 'running': if vpc_id in map(lambda x: x['VPCId'], private_hosted_zone_properties['VPCs']): vpc_associated = True @@ -770,7 +778,8 @@ def lambda_handler( reversed_ip_address, 'in-addr.arpa', 'PTR', - private_dns_name + fqdn +# private_dns_name ) caller_response.append('Created PTR record in zone id: ' + @@ -778,7 +787,8 @@ def lambda_handler( ' for hosted zone ' + str(reversed_ip_address) + 'in-addr.arpa with value: ' + - str(private_dns_name)) + str(fqdn)) +# str(private_dns_name)) else: LOGGER.debug("No reverse zone associated with VPC - skipping creating resource records %s", lineno()) @@ -847,14 +857,16 @@ def lambda_handler( reversed_ip_address, 'in-addr.arpa', 'PTR', - private_dns_name + fqdn +# private_dns_name ) caller_response.append('Deleted PTR record in zone id: ' + str(reverse_lookup_zone_id) + ' for hosted zone ' + str(reversed_ip_address) + 'in-addr.arpa with value: ' + - str(private_dns_name)) + str(fqdn)) +# str(private_dns_name)) else: delete_resource_record( route53, @@ -1239,7 +1251,7 @@ def change_resource_recordset(client, zone_id, host_name, hosted_zone_name, reco "ResourceRecordSet": { "Name": host_name + hosted_zone_name, "Type": record_type, - "TTL": 60, + "TTL": DNS_RR_TTL, "ResourceRecords": [ { "Value": value @@ -1336,7 +1348,7 @@ def delete_resource_record(client, zone_id, host_name, hosted_zone_name, record_ "ResourceRecordSet": { "Name": host_name + hosted_zone_name, "Type": record_type, - "TTL": 60, + "TTL": DNS_RR_TTL, "ResourceRecords": [ { "Value": value diff --git a/code/ddns-lambda.zip b/code/ddns-lambda.zip index 8147b70..09d2410 100644 Binary files a/code/ddns-lambda.zip and b/code/ddns-lambda.zip differ diff --git a/version.tf b/version.tf index 4e8c3aa..8eb9976 100644 --- a/version.tf +++ b/version.tf @@ -1,3 +1,3 @@ locals { - _module_version = "0.0.13" + _module_version = "0.0.14" }