def network_interface(function, credentials, unused_resource_count, region_list):
    print('Scanning Network Interfaces')
    ni_count = 0
    unused_ni_detail = []
    for region in region_list:
        try:
            ec2 = boto3.resource('ec2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            network_interfaces = list(ec2.network_interfaces.all())
            unused_nis = set([ni.network_interface_id for ni in network_interfaces if (ni.status == 'available')])
            for network_interface_id in unused_nis:
                unused_ni_detail.append({'ResourceType': 'AWS::EC2::NetworkInterface', 'ResourceId': network_interface_id, 'Region': region})
            ni_count += len(unused_nis)
        except:
            pass
    if ni_count:
        unused_ni_detail = json.loads(json.dumps(unused_ni_detail))
        f = csv.writer(open('./aws_logs/network_interface.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_ni_detail in unused_ni_detail:
            f.writerow([unused_ni_detail['ResourceType'], unused_ni_detail['ResourceId'], unused_ni_detail['Region']])
    unused_resource_count[function] = ni_count
def network_interface(function, credentials, unused_resource_count, region_list):
    print('Scanning Network Interfaces')
    ni_count = 0
    unused_ni_detail = []
    for region in region_list:
        try:
            ec2 = boto3.resource('ec2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            network_interfaces = list(ec2.network_interfaces.all())
            unused_nis = set([ni.network_interface_id for ni in network_interfaces if (ni.status == 'available')])
            for network_interface_id in unused_nis:
                unused_ni_detail.append({'ResourceType': 'AWS::EC2::NetworkInterface', 'ResourceId': network_interface_id, 'Region': region})
            ni_count += len(unused_nis)
        except:
            pass
    if ni_count:
        unused_ni_detail = json.loads(json.dumps(unused_ni_detail))
        f = csv.writer(open('./aws_logs/network_interface.csv', 'w', newline=))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_ni_detail in unused_ni_detail:
            f.writerow([unused_ni_detail['ResourceType'], unused_ni_detail['ResourceId'], unused_ni_detail['Region']])
    unused_resource_count[function] = ni_count