def app_nw_gateway_loadbalancer(function, credentials, unused_resource_count, region_list):
    print('Scanning Application/Network/Gateway Load balancers')
    elbv2_count = 0
    unused_elbv2_detail = []
    for region in region_list:
        try:
            elbv2 = boto3.client('elbv2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            paginated_data = []
            elbv2_paginator = elbv2.get_paginator('describe_load_balancers')
            for load_balancers in elbv2_paginator.paginate():
                paginated_data.extend(load_balancers['LoadBalancers'])
            for elbv2_detail in paginated_data:
                target_health_status = []
                try:
                    target_group_detail = elbv2.describe_target_groups(LoadBalancerArn=elbv2_detail['LoadBalancerArn'])['TargetGroups']
                    for target_group in target_group_detail:
                        target_group_health = elbv2.describe_target_health(TargetGroupArn=target_group['TargetGroupArn'])['TargetHealthDescriptions']
                        for target in target_group_health:
                            target_health_status.append(target['TargetHealth']['State'])
                except:
                    pass
                if ('healthy' not in target_health_status):
                    unused_elbv2_detail.append({'ResourceType': 'AWS::ElasticLoadBalancingV2::LoadBalancer', 'LoadBalancer_Type': elbv2_detail['Type'], 'ResourceId': elbv2_detail['LoadBalancerName'], 'Region': region})
                    elbv2_count += 1
        except:
            pass
    if elbv2_count:
        unused_elbv2_detail = json.loads(json.dumps(unused_elbv2_detail))
        f = csv.writer(open('./aws_logs/app_nw_gateway_loadbalancer.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'LoadBalancer_Type', 'ResourceId', 'Region'])
        for unused_elbv2_detail in unused_elbv2_detail:
            f.writerow([unused_elbv2_detail['ResourceType'], unused_elbv2_detail['LoadBalancer_Type'], unused_elbv2_detail['ResourceId'], unused_elbv2_detail['Region']])
    unused_resource_count[function] = elbv2_count
def app_nw_gateway_loadbalancer(function, credentials, unused_resource_count, region_list):
    print('Scanning Application/Network/Gateway Load balancers')
    elbv2_count = 0
    unused_elbv2_detail = []
    for region in region_list:
        try:
            elbv2 = boto3.client('elbv2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            paginated_data = []
            elbv2_paginator = elbv2.get_paginator('describe_load_balancers')
            for load_balancers in elbv2_paginator.paginate():
                paginated_data.extend(load_balancers['LoadBalancers'])
            for elbv2_detail in paginated_data:
                target_health_status = []
                try:
                    target_group_detail = elbv2.describe_target_groups(LoadBalancerArn=elbv2_detail['LoadBalancerArn'])['TargetGroups']
                    for target_group in target_group_detail:
                        target_group_health = elbv2.describe_target_health(TargetGroupArn=target_group['TargetGroupArn'])['TargetHealthDescriptions']
                        for target in target_group_health:
                            target_health_status.append(target['TargetHealth']['State'])
                except:
                    pass
                if ('healthy' not in target_health_status):
                    unused_elbv2_detail.append({'ResourceType': 'AWS::ElasticLoadBalancingV2::LoadBalancer', 'LoadBalancer_Type': elbv2_detail['Type'], 'ResourceId': elbv2_detail['LoadBalancerName'], 'Region': region})
                    elbv2_count += 1
        except:
            pass
    if elbv2_count:
        unused_elbv2_detail = json.loads(json.dumps(unused_elbv2_detail))
        f = csv.writer(open('./aws_logs/app_nw_gateway_loadbalancer.csv', 'w', newline=))
        f.writerow(['ResourceType', 'LoadBalancer_Type', 'ResourceId', 'Region'])
        for unused_elbv2_detail in unused_elbv2_detail:
            f.writerow([unused_elbv2_detail['ResourceType'], unused_elbv2_detail['LoadBalancer_Type'], unused_elbv2_detail['ResourceId'], unused_elbv2_detail['Region']])
    unused_resource_count[function] = elbv2_count