Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock AWS SDK2 (S3) in Java

So I want to mock AWS SDK 2.x (only S3 service), so that test upload and download files to a bucket without a real AWS. I'm looking for a Java implementations.

I found a lot what implements (Adobe S3Mock ...etc), but all of them uses AWS SDK 1.x.

like image 692
Gábor Csikós Avatar asked Apr 04 '19 08:04

Gábor Csikós


People also ask

Is S3 client thread safe Java?

All the clients in the AWS SDK for Java are thread safe and you should to reuse client objects.

How do I use AWS SDK in Jmeter?

AWS IAM UserLogin into your AWS account and open IAM service. Click Users under Access Management. Click Add users button to set the user details and credential type as shown below. Enter jmeter-s3-access in User name and check Access key - Programmatic access .

Does S3 Putobject overwrite?

If an object already exists in a bucket, the new object will overwrite it because Amazon S3 stores the last write request.


1 Answers

You shouldn't re-implement the S3 API yourself. Instead, use one of the existing tools like localstack, MinIO, OpenStack Swift and others. They all provide S3-compatible API (though some dif ferences can be). The best one for tests is localstack, IMHO.It is available as a Docker image, so you can use it locally or in your CI pipelines.

Not to the Java part of your question. If you are a lucky user of JUnit 5 I would recommend you to use aws-junit5, a set of JUnit 5 extensions for AWS. And, yes, I am it's author. These extensions can be used to inject clients for AWS services provided by tools like localstack (actually, any AWS-compatible API is supported, including real AWS itself). Both AWS Java SDK v 2.x and v 1.x are supported. You can use aws-junit5 to inject clients for S3, DynamoDB, Kinesis, SES, SNS and SQS.

Read more in the user guide, it even has a section about CI configuration with GitHub.

like image 82
madhead - StandWithUkraine Avatar answered Oct 20 '22 02:10

madhead - StandWithUkraine