diff --git a/CHANGELOG.md b/CHANGELOG.md index 68bc693..ec4f5ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,3 +139,8 @@ * 2.0.3 -- 2023-05-11 - code 2.0.3 - fix emr cluster detection + +* 2.0.4 -- 2023-05-17 + - code 2.0.4 + - add context info and event id to SNS messages + - add heritage mismatch information to output diff --git a/code/ddns-lambda.py b/code/ddns-lambda.py index 25bdc93..b3b7cf7 100755 --- a/code/ddns-lambda.py +++ b/code/ddns-lambda.py @@ -73,7 +73,7 @@ LOGGER = logging.getLogger() account_id = None region = None -VERSION = '2.0.3' +VERSION = '2.0.4' # Read Env variables DEBUG_LOG_LEVEL = os.environ.get('DebugLogLevel', 'INFO') @@ -319,6 +319,10 @@ def lambda_handler( sns_msg['region'] = event['region'] sns_msg['event'] = str(event) sns_msg['context'] = str(context) + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['message'] = caller_response[-1] publish_to_sns(sns_client, json.dumps(sns_msg)) return caller_response @@ -338,6 +342,10 @@ def lambda_handler( sns_msg['instance_id'] = event['detail']['instance-id'] sns_msg['account_id'] = account_id sns_msg['region'] = event['region'] + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['message'] = 'DynamoDB table does not exist: ' + DDBNAME publish_to_sns(sns_client, json.dumps(sns_msg)) return caller_response @@ -511,6 +519,10 @@ def lambda_handler( sns_msg['instance_id'] = instance_id sns_msg['account_id'] = account_id sns_msg['region'] = region + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'ec2' sns_msg['boto3_method'] = 'describe_vpc_attribute' sns_msg['message'] = "You have to enable DNS hostnames to use Route 53 private hosted zones. DNS hostnames disabled for " + vpc_id @@ -529,6 +541,10 @@ def lambda_handler( sns_msg['instance_id'] = instance_id sns_msg['account_id'] = account_id sns_msg['region'] = region + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'ec2' sns_msg['boto3_method'] = 'describe_vpc_attribute' sns_msg['message'] = "You have to enabled DNS support to use Route 53 private hosted zones. DNS support disabled for " + vpc_id @@ -624,6 +640,10 @@ def lambda_handler( sns_msg['instance_id'] = instance_id sns_msg['account_id'] = account_id sns_msg['region'] = region + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'ec2' sns_msg['boto3_method'] = 'describe_vpcs' sns_msg['message'] = 'No DHCP option set assigned to this VPC: ' + vpc_id @@ -1259,6 +1279,10 @@ def new_list_hosted_zones(client, instance_id): sns_msg = {} sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'list_hosted_zones' sns_msg['message'] = 'list_hosted_zones timed out' @@ -1336,6 +1360,10 @@ def new_list_hosted_zones_by_vpc(client, instance_id, vpc_id, region): sns_msg['vpc_id'] = vpc_id sns_msg['region'] = region sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'list_hosted_zones_by_vpc' sns_msg['message'] = 'list_hosted_zones_by_vpc timed out' @@ -1773,6 +1801,10 @@ def new_change_resource_recordset(oclient, instance_id, zone_id, host_name, host sns_msg = {} sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'change_resource_record_sets' sns_msg['message'] = 'change_resource_record_sets could not UPSERT record' @@ -1989,6 +2021,10 @@ def new_get_resource_record(oclient, instance_id, zone_id, host_name, hosted_zon sns_msg = {} sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'list_resource_record_sets' sns_msg['message'] = 'list_resource_record_sets timed out' @@ -2119,6 +2155,10 @@ def new_delete_resource_record(oclient, instance_id, zone_id, host_name, hosted_ sns_msg = {} sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'change_resource_record_sets' sns_msg['message'] = 'change_resource_record_sets could not DELETE record' @@ -2581,6 +2621,10 @@ def new_get_hosted_zone_properties(client, instance_id, zone_id): sns_msg = {} sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['client'] = 'route53' sns_msg['boto3_method'] = 'get_hosted_zone' sns_msg['message'] = 'get_hosted_zone timed out' @@ -2898,16 +2942,18 @@ def process_delete_records(route53, instance_id, zone_id, # Return the dictionary of the value with comma separated heritage = parse_heritage(heritage_value) - LOGGER.debug("heritage parsed data in string format: %s", str(heritage) + lineno()) + LOGGER.debug(f"heritage parsed data in string format: '{heritage}' {lineno()}") # check if the TXT record was created by the Lambda as match instance-id if verify_heritage_owner(heritage, HERITAGE_TAG): - LOGGER.debug("TXT record was created by Lambda DDNS %s", - HERITAGE_TAG + lineno()) + LOGGER.debug( + f"TXT record was created by Lambda DDNS tag application '{HERITAGE_TAG}' {lineno()}") heritage_own = True else: - LOGGER.info("TXT record was not created by Lambda DDNS %s", - HERITAGE_TAG + lineno()) + LOGGER.info( + f"TXT record was not created by Lambda DDNS tag application '{HERITAGE_TAG}' {lineno()}") + LOGGER.info(f"found_record is '{heritage_value}' {lineno()}") + LOGGER.info(f"parsed heritage is is '{heritage}' {lineno()}") heritage_own = False if compare_heritage(heritage, 'instance_id', instance_id): @@ -2915,6 +2961,8 @@ def process_delete_records(route53, instance_id, zone_id, heritage_instance_match = True else: LOGGER.info("TXT record does not match instance_id: %s", instance_id + lineno()) + LOGGER.info(f"found_record is '{heritage_value}' {lineno()}") + LOGGER.info(f"parsed heritage is is '{heritage}' {lineno()}") heritage_instance_match = False # delete A/PTR/AAAA/CNAME record @@ -2980,6 +3028,10 @@ def process_delete_records(route53, instance_id, zone_id, if SNS_ENABLE: try: sns_msg = {} + sns_msg['event_id'] = event['id'] + sns_msg['aws_request_id'] = context.aws_request_id + sns_msg['log_group_name'] = context.log_group_name + sns_msg['log_stream_name'] = context.log_stream_name sns_msg['instance_id'] = instance_id sns_msg['account_id'] = get_caller_account_id() sns_msg['message'] = 'TXT record does not match. Will not delete the A/PTR/CNAME/AAAA record.' @@ -3096,7 +3148,8 @@ def tags_to_dict(tags): tag_dict = {} if len(tags) > 0: - tag_dict = {tag.get('Key', '').lstrip().rstrip(): tag.get('Value', '') for tag in tags} + tag_dict = {tag.get('Key', '').lstrip().rstrip() + : tag.get('Value', '') for tag in tags} return tag_dict diff --git a/code/ddns-lambda.zip b/code/ddns-lambda.zip index fc87b90..f50badb 100644 Binary files a/code/ddns-lambda.zip and b/code/ddns-lambda.zip differ diff --git a/version.tf b/version.tf index 4ab7a1f..f033f34 100644 --- a/version.tf +++ b/version.tf @@ -1,3 +1,3 @@ locals { - _module_version = "2.0.3" + _module_version = "2.0.4" }