Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 29, 2023
1 parent a3e64f5 commit f8ce60c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
LOGGER = logging.getLogger()
account_id = None
region = None
VERSION = '2.0.1'
VERSION = '2.0.2'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -800,10 +800,19 @@ def lambda_handler(
f"instance: {instance_id}, final names for A and PTR record host {f_hostname} zone {f_zonename} fqdn {final_private_dns_name} ptr-fqdn {p_fqdn} {lineno()}")

# Get the PHZ ID for the Zone
zone_data_forward = zone_data_tuple(
*phz_collection_by_vpc[final_hosted_zone_name].values())
zone_data_reverse = zone_data_tuple(
*phz_collection_by_vpc[tag_data['ptr_entry'].zonename].values())
zone_forward_item = phz_collection_by_vpc.get(final_hosted_zone_name, {})
if zone_forward_item:
zone_data_forward = zone_data_tuple(
*phz_collection_by_vpc[final_hosted_zone_name].values())
else:
zone_data_forward = zone_data_tuple(None, None, None, None, None)

zone_reverse_item = phz_collection_by_vpc.get(tag_data['ptr_entry'].zonename], {})
if zone_reverse_item:
zone_data_reverse = zone_data_tuple(*phz_collection_by_vpc[tag_data['ptr_entry'].zonename].values())
else:
zone_data_reverse = zone_data_tuple(None, None, None, None, None)

# final_hosted_zone_item = phz_collection_by_vpc[final_hosted_zone_name]
# final_hosted_zone_id = zone_data_forward.zone_id
# final_hosted_zone_owner = final_hosted_zone_item['owner_account']
Expand All @@ -815,7 +824,7 @@ def lambda_handler(
f"private_hosted_zone: zone_id {zone_data_forward.zone_id} is_mine {zone_data_forward.owner_account==account_id} owner {zone_data_forward.owner_account}: {lineno()}")

# create the TXT heritage record
heritage = initialize_heritage(HERITAGE_TAG, VERSION,
heritage=initialize_heritage(HERITAGE_TAG, VERSION,
{
'account_id': account_id,
'region': region,
Expand All @@ -834,7 +843,7 @@ def lambda_handler(
# Create OR Delete the A / PTR Record
if state == 'running':
dns_data = []
if not flags['noforward']:
if not flags['noforward'] and zone_data_forward.zone_id:
# create the records
try:
LOGGER.debug("Creating resource records %s", lineno())
Expand Down Expand Up @@ -901,10 +910,14 @@ def lambda_handler(
LOGGER.error("instance: %s, unexpected error. %s\n",
instance_id, str(err) + lineno())
else:
if not zone_data_forward.zone_id:
LOGGER.info(
f"not adding A and heritage TXT for host {final_private_hostname} zone {zone_data_forward.name} no such zone value {private_ip}")
else:
LOGGER.info(
f"flags=noforward, not adding A and heritage TXT for host {final_private_hostname} zone {zone_data_forward.name} value {private_ip}")

if not flags['noptr']:
if not flags['notpr'] and zone_data_reverse.zone_id:
# fqdn = create_fqdn(final_private_hostname, final_hosted_zone_name)
try:
if reverse_zone_associated:
Expand Down Expand Up @@ -972,7 +985,11 @@ def lambda_handler(
LOGGER.error("instance: %s, unexpected error. %s\n",
instance_id, str(err) + lineno())
else:
LOGGER.info(
if not zone_data_reverse.zone_id:
LOGGER.info(
f"not adding PTR and heritage TXT for host {tag_data['ptr_entry'].hostname} zone {tag_data['ptr_entry'].zonename} no such zone value {final_private_dns_name}")
else:
LOGGER.info(
f"flags=noptr, not adding PTR and heritage TXT for host {tag_data['ptr_entry'].hostname} zone {tag_data['ptr_entry'].zonename} value {final_private_dns_name}")

# else: # not running so delete the records. Note this may leave orphans around if the flags are set and then the host is shut down. We may want to remove no matter what.
Expand Down Expand Up @@ -1009,12 +1026,16 @@ def lambda_handler(
# cname_domain_suffix_id = cname_domain_suffix_item['zone_id']
# LOGGER.debug("cname_domain_suffix_id: %s", str(cname_domain_suffix_id))

cf_zonename_id = phz_collection_by_vpc[cf_zonename]['zone_id']
cf_zonename_item = phz_collection_by_vpc.get(cf_zonename,None)
if cf_zonename_item:
cf_zonename_id = cf_zonename_item['zone_id']
else:
cf_zonename_id = None
LOGGER.debug(f"cname_domain_suffix_id: {cf_zonename_id}")

# create CNAME record in private zone
if state == 'running':
if not flags['nocname'] and (all([emr_status.is_cluster, emr_status.is_master]) or not emr_status.is_cluster):
if not flags['nocname'] cf_zonename_id and (all([emr_status.is_cluster, emr_status.is_master]) or not emr_status.is_cluster):
try:
LOGGER.debug(f"cname_host_name: {cf_hostname} {lineno()}")
LOGGER.debug(f"cname_domain_suffix: {cf_zonename} {lineno()}")
Expand Down Expand Up @@ -1093,6 +1114,9 @@ def lambda_handler(
if emr_status.is_cluster:
LOGGER.info(
f"instance {instance_id}: is_cluster && not is_master cluster_id {emr_status.cluster_id} NOT setting CNAME {cf_hostname} in zone {cf_zonename} {lineno()}")
elif not cf_zonename_id:
LOGGER.info(
f"instance {instance_id}: NOT setting CNAME {cf_hostname} in zone {cf_zonename} no such zone {lineno()}")

#
# update ddb entry to include dns entries written to be able to delete them properly
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit f8ce60c

Please sign in to comment.