DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Video Generation With Java: Leverage Nova and Amazon Bedrock
  • Leverage Amazon BedRock Chat Model With Java and Spring AI
  • Expert Guide: How to Slash Cloud Cost in 2025
  • Using SQS With JMS for Legacy Applications

Trending

  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Measuring the Impact of AI on Software Engineering Productivity
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Scan an AWS S3 File for Viruses in Java

Scan an AWS S3 File for Viruses in Java

With cloud storage becoming a widespread solution for businesses, it’s important to perform reliable scans to identify threats and prevent further infection.

By 
Brian O'Neill user avatar
Brian O'Neill
DZone Core CORE ·
Jan. 16, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.3K Views

Join the DZone community and get the full member experience.

Join For Free

The increased use of cloud storage is also increasing the attention it gets from potential cyber attackers. End-users are able to upload viruses, and attackers can craft specialized attack malware and upload this content as well. Once these threats are uploaded, they can flow through your systems, hiding themselves in cloud storage or databases, and could eventually get executed.

Consider the following situation: an attacker uploads a custom executable file into a financial company’s cloud storage database, and the system accepts it. The virus is missed by the company’s minimal virus scan software, so it continues to infiltrate other critical business applications. Eventually, it’s downloaded by a financial manager, resulting in an endpoint being infected with an Advanced Persistent Threat (APT).

So how can we ensure our cloud storage (in this case an AWS S3 file) is free from these threats? We need a solution that will not only tell us if the file is clean, but also identify the virus if present. Here, we'll take a look at a free solution for Java that can scan cloud storage for multiple threats by leveraging a database of over 17 million virus signatures that is updated every 15 minutes via the cloud.

To begin, we will install the library by adding the Maven repository:

XML
xxxxxxxxxx
1
 
1
<repositories>
2
    <repository>
3
        <id>jitpack.io</id>
4
        <url>https://jitpack.io</url>
5
    </repository>
6
</repositories>

Then, add the Maven dependency:

XML
xxxxxxxxxx
1
 
1
<dependencies>
2
<dependency>
3
    <groupId>com.github.Cloudmersive</groupId>
4
    <artifactId>Cloudmersive.APIClient.Java</artifactId>
5
    <version>v3.54</version>
6
</dependency>
7
</dependencies>

Now, we want to scan the scan the AWS S3 file for viruses. To prevent any wait time for our users, the scanning system provides a subsecond response, enabling the user to immediately take action if a threat is detected.

At the top of our controller we should add these imports:

Java
 




xxxxxxxxxx
1


 
1
// Import classes:
2
//import com.cloudmersive.client.invoker.ApiClient;
3
//import com.cloudmersive.client.invoker.ApiException;
4
//import com.cloudmersive.client.invoker.Configuration;
5
//import com.cloudmersive.client.invoker.auth.*;
6
//import com.cloudmersive.client.ScanCloudStorageApi;


Next, we will need to gather the following parameters to plug into the code:

  • API Key; retrieve a free forever API key from the Cloudmersive website that can scan 800 files/month
  • Access key for the S3 bucket; we can get this from My Security Credentials in the AWS Console
  • Secret key for the S3 bucket; this can be found in My Security Credentials as well
  • Name of the region of the S3 bucket (ex: US-East-1)
  • Name of the S3 bucket
  • Key name (a.k.a. file name) of the file in S3 you wish to scan for viruses

Lastly, we enter the following code into our controller:

Java
 




xxxxxxxxxx
1
22


 
1
ApiClient defaultClient = Configuration.getDefaultApiClient();
2

          
3
// Configure API key authorization: Apikey
4
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
5
Apikey.setApiKey("YOUR API KEY");
6
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
7
//Apikey.setApiKeyPrefix("Token");
8

          
9
ScanCloudStorageApi apiInstance = new ScanCloudStorageApi();
10
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
11
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
12
String bucketRegion = "bucketRegion_example"; // String | Name of the region of the S3 bucket, such as 'US-East-1'
13
String bucketName = "bucketName_example"; // String | Name of the S3 bucket
14
String keyName = "keyName_example"; // String | Key name (also called file name) of the file in S3 that you wish to scan for viruses
15
try {
16
    CloudStorageVirusScanResult result = apiInstance.scanCloudStorageScanAwsS3File(accessKey, secretKey, bucketRegion, bucketName, keyName);
17
    System.out.println(result);
18
} catch (ApiException e) {
19
    System.err.println("Exception when calling ScanCloudStorageApi#scanCloudStorageScanAwsS3File");
20
    e.printStackTrace();
21
}


Voila! This will return a lightning-fast result indicating if your AWS S3 file is free from viruses, malware, trojans, ransomware, and spyware. If a threat is found, the result will indicate the virus name, enabling the user to promptly address the issue and eradicate the virus.

In conclusion, we can see that being proactive in scanning our cloud storage for viruses is an important and necessary step in assuring the most secure experience for our business and users.

AWS Java (programming language) Cloud storage

Opinions expressed by DZone contributors are their own.

Related

  • Video Generation With Java: Leverage Nova and Amazon Bedrock
  • Leverage Amazon BedRock Chat Model With Java and Spring AI
  • Expert Guide: How to Slash Cloud Cost in 2025
  • Using SQS With JMS for Legacy Applications

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!