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 406eef6 commit cfe7dea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
59 changes: 46 additions & 13 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.0b58'
VERSION = '1.2.0b59'

# Read Env variables
DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO')
Expand Down Expand Up @@ -405,7 +405,7 @@ def lambda_handler(
try:
## LOGGER.info(f"instance_data type {type(instance)} {lineno()}")
## instance_data = json.loads(instance)
LOGGER.info(f"getting _DnsEntries {lineno()}")
## LOGGER.info(f"getting _DnsEntries {lineno()}")
dns_data_raw = instance.get('_DnsEntries', [])
LOGGER.info(
f"got _DnsEntries type {type(dns_data_raw)} value {dns_data_raw} {lineno()}")
Expand Down Expand Up @@ -1024,9 +1024,24 @@ def lambda_handler(
# append to the lsit
caller_response = caller_response + process_response['msg']

# Clean up DynamoDB after deleting records
if state != 'running':
# update ddb entry to include dns entries written to be able to delete them properly
if state == 'running':
try:
instance['_DnsEntries'] = [dict(d._asdict()) for d in dns]
instance = remove_empty_from_dict(instance)
instance_dump = json.dumps(instance, default=json_serial)
instance_attributes = instance_dump
LOGGER.info(
f"Updating DDB Entry item for {instance_id} to include DNS entries {lineno()}")
put_item_in_dynamodb_table(
dynamodb_client, DDBNAME, instance_id, instance_attributes)
LOGGER.debug(f"Done updating item in dynamodb table {lineno()}")
except Exception as err:
LOGGER.error(
f"Error putting item in DDB table {instance_id} error {err} {lineno()}")

# Clean up DynamoDB after deleting records
if state != 'running':
# only if all records were succesfully deleted
if delete_records:
delete_item_from_dynamodb_table(dynamodb_client, DDBNAME, instance_id)
Expand Down Expand Up @@ -1054,15 +1069,15 @@ def lambda_handler(
return caller_response


def put_instance_dns_data_item(dynamodb_client, DDBNAME, instance_id, dns):
dns_list = [dict(d._asdict()) for d in dns]
# dns_info = json.dumps(dns_list, default=json_serial)
dns_info = json.dumps(dns_list)

LOGGER.debug(f"put dns data into {instance_id}/dns: {str(dns_info)}: {lineno()}")
put_item_in_dynamodb_table(dynamodb_client, DDBNAME, f'{instance_id}/dns', dns_info)
LOGGER.debug(f"done putting dns item in dynamo table {lineno()}")
return
# def put_instance_dns_data_item(dynamodb_client, DDBNAME, instance_id, dns):
## dns_list = [dict(d._asdict()) for d in dns]
# dns_info = json.dumps(dns_list, default=json_serial)
## dns_info = json.dumps(dns_list)
##
## LOGGER.debug(f"put dns data into {instance_id}/dns: {str(dns_info)}: {lineno()}")
## put_item_in_dynamodb_table(dynamodb_client, DDBNAME, f'{instance_id}/dns', dns_info)
## LOGGER.debug(f"done putting dns item in dynamo table {lineno()}")
# return


def get_cname_from_tags(tags):
Expand Down Expand Up @@ -3115,3 +3130,21 @@ def create_fqdn(host, zone):
fqdn = host.replace(zone, '').rstrip('.') + '.' + zone
fqdn += '.' if fqdn[-1] != '.' else ''
return fqdn


aws: elasticmapreduce: job - flow - id        j - 8O514K6HPIYZ
A2      GenerateCertificate     FALSE
A2      Webhook 1680546860
A2      StackName       DAS - REL - groupii - dashboard - integration - docim
A2      CAMPAIGN_NAME   ashen
A2      DontPatch       true
A2      ProjectNumber   fs0000000033
A2      NoBootstrap     FALSE
A2      RunConfiguration        NMFv73State
A2      ClusterSize     Small2
A2      FRIENDLY_NAME   docim
A2      CloudWatchEnable        FALSE
A2      ModeOfOperation MODE2: Run Group II Safetab P
A2      LightsOut       true
A2      POC     Ryan Kane
A2      aws: elasticmapreduce: instance - group - role        MASTER
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit cfe7dea

Please sign in to comment.