def delete_health_check(self, health_check_id): """ :return: """ route53 = modules.route53.Route53() route53.delete_health_check(health_check_id)
def ec2_terminate_event(ec2_instance_id): """ When an ec2 instance is terminated, the DNS record and health check for this server is removed """ # config settings = configparser.ConfigParser() settings.read('config.ini') logging.info("Event: ec2_termination_event") logging.info("Working on ec2-instance id: " + ec2_instance_id) logging.info("Using route53 hosted zone id: " + settings.get('route53', 'hosted_zone')) logging.info("Domain name: " + settings.get('route53', 'domain_name')) # Get the DNS name to a simple or weighted dns_name = '' if settings.get('dns_record_type', 'type') == 'simple': dns_name = ec2_instance_id + '.' + settings.get( 'route53', 'domain_name') elif settings.get('dns_record_type', 'type') == 'weighted': dns_name = settings.get('dns_record_type', 'dns_name') + '.' + settings.get( 'route53', 'domain_name') # init route53 object route53 = modules.route53.Route53() route53.set_hosted_zone_id(settings.get('route53', 'hosted_zone')) health_check_id = route53.get_health_check_by_tag('instance-id', ec2_instance_id) instance_public_ip = route53.get_health_check_tag_value( ec2_instance_id, 'instance-public-ip') # Delete DNS record resource_record_set_dict = { 'Name': dns_name, 'Type': settings.get('dns_record_set', 'type'), 'SetIdentifier': ec2_instance_id, 'Weight': int(settings.get('dns_record_set', 'Weight')), 'TTL': int(settings.get('dns_record_set', 'TTL')), 'ResourceRecords': [ { 'Value': instance_public_ip }, ], 'HealthCheckId': health_check_id } logging.debug(resource_record_set_dict) try: response_delete_resource_record_sets = route53.create_resource_record_sets( 'DELETE', resource_record_set_dict, '') logging.debug(response_delete_resource_record_sets) except: logging.info("Unable to delete the record set") logging.info(resource_record_set_dict) # Search for health check via tag searched_health_check_id = route53.get_health_check_by_tag( 'instance-id', ec2_instance_id) # Delete health check try: delete_response = route53.delete_health_check(searched_health_check_id) except: logging.info("Unable to delete the health check")
def ec2_terminate_event(ec2_instance_id): """ When an ec2 instance is terminated, the DNS record and health check for this server is removed """ # config settings = configparser.ConfigParser() settings.read('config.ini') logging.info("Event: ec2_termination_event") logging.info("Working on ec2-instance id: "+ec2_instance_id) logging.info("Using route53 hosted zone id: "+settings.get('route53', 'hosted_zone')) logging.info("Domain name: "+settings.get('route53', 'domain_name')) # Get the DNS name to a simple or weighted dns_name = '' if settings.get('dns_record_type', 'type') == 'simple': dns_name = ec2_instance_id+'.'+settings.get('route53', 'domain_name') elif settings.get('dns_record_type', 'type') == 'weighted': dns_name = settings.get('dns_record_type', 'dns_name')+'.'+settings.get('route53', 'domain_name') # init route53 object route53 = modules.route53.Route53() route53.set_hosted_zone_id(settings.get('route53', 'hosted_zone')) health_check_id = route53.get_health_check_by_tag('instance-id', ec2_instance_id) instance_public_ip = route53.get_health_check_tag_value(ec2_instance_id, 'instance-public-ip') # Delete DNS record resource_record_set_dict = { 'Name': dns_name, 'Type': settings.get('dns_record_set', 'type'), 'SetIdentifier': ec2_instance_id, 'Weight': int(settings.get('dns_record_set', 'Weight')), 'TTL': int(settings.get('dns_record_set', 'TTL')), 'ResourceRecords': [ { 'Value': instance_public_ip }, ], 'HealthCheckId': health_check_id } logging.debug(resource_record_set_dict) try: response_delete_resource_record_sets = route53.create_resource_record_sets('DELETE', resource_record_set_dict, '') logging.debug(response_delete_resource_record_sets) except: logging.info("Unable to delete the record set") logging.info(resource_record_set_dict) # Search for health check via tag searched_health_check_id = route53.get_health_check_by_tag('instance-id', ec2_instance_id) # Delete health check try: delete_response = route53.delete_health_check(searched_health_check_id) except: logging.info("Unable to delete the health check")