Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 26, 2023
1 parent a132acc commit d59e095
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
29 changes: 17 additions & 12 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 = '1.2.0b56'
VERSION = '1.2.0b57'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -373,6 +373,10 @@ def lambda_handler(
LOGGER.info("instance: %s, no instance data, repeat check: %s",
instance_id, lineno())

# instance object to/from DDB contains the instance data from get_instances (Reservations).
# We are adding a fake entry to it _DnsEntries to store what was added by the code, so we can also easily remove it later
# to avoid orphaned records

# Remove response metadata from the response
if 'ResponseMetadata' in instance:
instance.pop('ResponseMetadata')
Expand All @@ -391,21 +395,22 @@ def lambda_handler(
put_item_in_dynamodb_table(dynamodb_client, DDBNAME,
instance_id, instance_attributes)
LOGGER.debug("done putting item in dynamo table %s", lineno())
dns_data = []
else:
# state is stopping or terminating
# Fetch item from DynamoDB
LOGGER.info("Fetching instance information from dynamodb %s", lineno())
instance = get_item_from_dynamodb_table(dynamodb_client, DDBNAME, instance_id)
LOGGER.info("instance attributes: %s", str(instance) + lineno())

## LOGGER.info(f"Fetching instance DNS information from dynamodb {lineno()}")
# instance_dns_data = get_item_from_dynamodb_table(
# dynamodb_client, DDBNAME, f'{instance_id}/dns')
## LOGGER.info(f"got instance dns data: {instance_dns_data}")
# if instance_dns_data:
# instance_dns_data_dict = json.loads(instance_dns_data, default=json_serial)
## instance_dns_data_dict = json.loads(instance_dns_data)
# LOGGER.info(
# f"instance dns data: {str(instance_dns_data)} length {len(instance_dns_data_dict)} {lineno()}")
try:
instance_data = json.loads(instance)
dns_data_raw = instance_data.get('_DnsEntries', [])
dns_data = [dns_data_tuple(**item) for item in dns_data_raw]
LOGGER.info(
f"Found entries from DDB for DNS records: {str(dns_data)} {lineno()}")
except:
LOGGER.error(f"Cannot deserialize instance data from DDB {lineno()}")
dns_data = []

# Get the instance tags and reorder them because we want a zone created before CNAME
try:
Expand Down Expand Up @@ -732,9 +737,9 @@ def lambda_handler(
" %s", str(heritage_value) + lineno())
delete_records = True

dns_data = []
# Create OR Delete the A / PTR Record
if state == 'running':
dns_data = []
if not flags['noforward']:
# create the records
try:
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit d59e095

Please sign in to comment.