[FIXED] How I can use S3Client with S3TransferManager in aws adk version 2?

Issue

I am working on java project and using aws sdk version 2 library to use s3 services. I am using S3Client for using services like getObject(),getBucekt,listObject etc.
And I want to use S3TransactionManager for get logging process of upload and download file.
Here are my code sample:-

       static String sAccessKey = "XXXXXXXXXX";
    static String sSecretKey = "XXXXXXXXXXXXX";
    static AwsBasicCredentials awsCreds = AwsBasicCredentials.create(
            sAccessKey,
            sSecretKey);
    AwsCredentialsProvider awsCredentialsProvider = StaticCredentialsProvider.create(awsCreds);
   static S3Client s3Client = S3Client.builder().region(Region.US_WEST_2)
            .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
            .build();
S3TransferManager s3TransferManager = S3TransferManager
            .builder()
            .s3ClientConfiguration(S3ClientConfiguration.builder()
                    .region(Region.US_WEST_2)
                    .credentialsProvider(awsCredentialsProvider).build()).build();


    S3TransferManager s3TransferManager1 = S3TransferManager.create();
    Region region = Region.US_WEST_2;
    S3ClientConfiguration s3ClientConfiguration =
            S3ClientConfiguration.builder()
                    .region(region)
                    .credentialsProvider(awsCredentialsProvider)
                    .targetThroughputInGbps(20.0)
                    .build();

    Upload upload =
            s3TransferManager1.upload(b -> b.putObjectRequest(r -> r.bucket("SSSS").key("test.ppt"))
                    .source(Paths.get("fileToUpload.txt")));

My issue is that when I used both s3 and s3_transaction_manager jar then I am getting error while creating object of S3TransactionManger.
Error are:-

Exception in thread "main" java.lang.NoSuchMethodError: software.amazon.awssdk.utils.Validate.isPositiveOrNull(Ljava/lang/Double;Ljava/lang/String;)Ljava/lang/Double;
at software.amazon.awssdk.transfer.s3.S3ClientConfiguration.<init>(S3ClientConfiguration.java:49)
at software.amazon.awssdk.transfer.s3.S3ClientConfiguration.<init>(S3ClientConfiguration.java:37)
at software.amazon.awssdk.transfer.s3.S3ClientConfiguration$DefaultBuilder.build(S3ClientConfiguration.java:301)
at software.amazon.awssdk.transfer.s3.S3ClientConfiguration$DefaultBuilder.build(S3ClientConfiguration.java:243)
at software.amazon.awssdk.transfer.s3.internal.DefaultS3TransferManager$DefaultBuilder.<init>(DefaultS3TransferManager.java:405)
at software.amazon.awssdk.transfer.s3.internal.DefaultS3TransferManager$DefaultBuilder.<init>(DefaultS3TransferManager.java:404)
at software.amazon.awssdk.transfer.s3.internal.DefaultS3TransferManager.builder(DefaultS3TransferManager.java:364)
at software.amazon.awssdk.transfer.s3.S3TransferManager.builder(S3TransferManager.java:497)
at com.bucketexplorer.main.SdkTest.main(SdkTest.java:88)

I think util class from both jar have conflict.

Jar files which I am using are :-

s3-2.16.46.jar
s3-transfer-manager-2.17.257-PREVIEW.jar

Please suggest how can I used both jar together?

Solution

It is a conflict between the two libraries.

Upgrading s3-2.16.46.jar to the same version of s3-transfer-manager (without PREVIEW) will solve the problem.

Answered By – dems98

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published