def ebs_volume(function, credentials, unused_resource_count, region_list):
    print('Scanning EBS Volumes')
    volume_count = 0
    unused_volume_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)
            volumes = list(ec2.volumes.all())
            unused_volumes = set([volume.volume_id for volume in volumes if (volume.state == 'available')])
            for volume_id in unused_volumes:
                unused_volume_detail.append({'ResourceType': 'AWS::EC2::Volume', 'ResourceId': volume_id, 'Region': region})
            volume_count += len(unused_volumes)
        except:
            pass
    if volume_count:
        unused_volume_detail = json.loads(json.dumps(unused_volume_detail))
        f = csv.writer(open('./aws_logs/ebs_volume.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_volume_detail in unused_volume_detail:
            f.writerow([unused_volume_detail['ResourceType'], unused_volume_detail['ResourceId'], unused_volume_detail['Region']])
    unused_resource_count[function] = volume_count
def ebs_volume(function, credentials, unused_resource_count, region_list):
    print('Scanning EBS Volumes')
    volume_count = 0
    unused_volume_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)
            volumes = list(ec2.volumes.all())
            unused_volumes = set([volume.volume_id for volume in volumes if (volume.state == 'available')])
            for volume_id in unused_volumes:
                unused_volume_detail.append({'ResourceType': 'AWS::EC2::Volume', 'ResourceId': volume_id, 'Region': region})
            volume_count += len(unused_volumes)
        except:
            pass
    if volume_count:
        unused_volume_detail = json.loads(json.dumps(unused_volume_detail))
        f = csv.writer(open('./aws_logs/ebs_volume.csv', 'w', newline=))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_volume_detail in unused_volume_detail:
            f.writerow([unused_volume_detail['ResourceType'], unused_volume_detail['ResourceId'], unused_volume_detail['Region']])
    unused_resource_count[function] = volume_count