How to Scan an AWS S3 File for Viruses in Python

2 min readJan 7, 2021

When you store business data in AWS S3, you want the content to be safe and secure. However, with new virus signatures popping up daily, it’s increasingly difficult to ensure that safety — this is where we come in. Utilizing the following API in Python, you will be able to quickly identify if the content of your AWS S3 file has been infected, which will enable you to eradicate the threat and prevent it from leaking to other business critical applications.

To install the Cloudmersive API, run this command to install the SDK:

pip install cloudmersive-virus-api-client

Next, you can call the function using the following code. Please note you will need to fill in the access key, secret key, bucket region, bucket name, and key name to instance the API.

from __future__ import print_function
import time
import cloudmersive_virus_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_virus_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_virus_api_client.ScanCloudStorageApi(cloudmersive_virus_api_client.ApiClient(configuration))
access_key = 'access_key_example' # str | AWS S3 access key for the S3 bucket; you can get this from My Security Credentials in the AWS console
secret_key = 'secret_key_example' # str | AWS S3 secret key for the S3 bucket; you can get this from My Security Credentials in the AWS console
bucket_region = 'bucket_region_example' # str | Name of the region of the S3 bucket, such as 'US-East-1'
bucket_name = 'bucket_name_example' # str | Name of the S3 bucket
key_name = 'key_name_example' # str | Key name (also called file name) of the file in S3 that you wish to scan for viruses
# Scan an AWS S3 file for viruses
api_response = api_instance.scan_cloud_storage_scan_aws_s3_file(access_key, secret_key, bucket_region, bucket_name, key_name)
except ApiException as e:
print("Exception when calling ScanCloudStorageApi->scan_cloud_storage_scan_aws_s3_file: %s\n" % e)

This will generate an instant response which will indicate if your file is infected, and if it is, the response will also identify which virus is responsible so you can address it. To retrieve the API Key, you can head to the Cloudmersive website to create an account and receive access to 800 free monthly calls across our library of APIs.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.