Using the S3 Java SDK to work with S3 compatible storage (minio)

I am trying to use aws-sdk-java AwsS3client to talk with a mini repository. From the CLI I can do:

aws --profile=minioplay  --endpoint-url https://play.minio.io:9000 s3 cp logback.xml s3://miniohstest-jixusroqeb --debug

this way using the default profile and user endpoint. Not sure how to do this (can I?) From java sdk. I roughly translated the above command awscliinto this scala fragment:

val cred = ...
val endpoint = "https://play.minio.io:9000"
val client = AmazonS3ClientBuilder
      .standard()
      .withCredentials(cred)
      .withEndpointConfiguration(
        new EndpointConfiguration(
          endpoint,
          AwsHostNameUtils.parseRegion(endpoint, AmazonS3Client.S3_SERVICE_NAME)
        )
      )
      .build()

Using the client above, I can fulfill very simple queries, for example:

client.listBuckets().asScala.foreach(println(_))

which is working. But when I try to do something advanced, for example:

val listRequest = new ListObjectsRequest()
      .withBucketName("miniohstest-jixusroqeb")
      //.withPrefix(r.getURI.getPath)
      //.withDelimiter(delimiter)

val res = client.listObjects(listRequest)
res.getObjectSummaries.forEach(x => println(x.getKey))

it throws the following exception:

Exception in thread "main" com.amazonaws.SdkClientException: Unable to execute HTTP request: miniohstest-jixusroqeb.play.minio.io
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1114)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1064)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)

What am I doing wrong?

+4
source share
1 answer

I solved it by installing withPathStyleAccessEnabled(true).

+5
source

Source: https://habr.com/ru/post/1694996/


All Articles