How to Scan an AWS S3 File for Viruses in Java
Are you using an AWS S3 file to store valuable content for your business? If so, you should take steps to ensure the safety of your information, as cloud storage is steadily becoming a main target for cyberattacks. By utilizing the following API, you will be checking the content of your file against a database of over 17 million virus signatures and malware, giving you a great start on protecting your business and clients from potential infection.
First off, let’s install the SDK with Maven by adding a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, add a reference to the dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>
Now, you can call the function with the following code:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ScanCloudStorageApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");ScanCloudStorageApi apiInstance = new ScanCloudStorageApi();
String accessKey = "accessKey_example"; // String | AWS S3 access key for the S3 bucket; you can get this from My Security Credentials in the AWS console
String secretKey = "secretKey_example"; // String | AWS S3 secret key for the S3 bucket; you can get this from My Security Credentials in the AWS console
String bucketRegion = "bucketRegion_example"; // String | Name of the region of the S3 bucket, such as 'US-East-1'
String bucketName = "bucketName_example"; // String | Name of the S3 bucket
String keyName = "keyName_example"; // String | Key name (also called file name) of the file in S3 that you wish to scan for viruses
try {
CloudStorageVirusScanResult result = apiInstance.scanCloudStorageScanAwsS3File(accessKey, secretKey, bucketRegion, bucketName, keyName);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ScanCloudStorageApi#scanCloudStorageScanAwsS3File");
e.printStackTrace();
}
Once the API is complete, you’ll receive a response identifying the virus (if found) or informing you that your content is resting safely without a virus in sight. Your personal API key can be retrieved from the Cloudmersive website; this will give you access to 800 monthly calls across our library of APIs.