OVHcloud Community

Welcome to your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Using aws sdk (java 2.x) to access S3/Swift Object Storage


#1

Is Swift Object Storage compatible with the “standard” aws sdk (v. 2.0) ?

Here my code to create a S3Client:
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(
“accessKeyId”,
“secretAccessKey”);

    client = S3Client.builder()
        .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
        .region(????)
        .build();

I found my accessKeyId and secretAccessKey, but I can’t set a proper vaue for “region”, because it is NOT a string, but an instance of software.amazon.awssdk.regions.Region class, that has a predefined values only (I think I should pass “gra”).
Does that mean I cannot use this sdk? Do I have to use the REST API?


#2

Hi, solved by myself!
Use this code:

        Region gra = Region.of("gra");
        
        client = S3Client.builder()
                .region(gra)
                .endpointOverride(URI.create("https://s3.gra.cloud.ovh.net"))                    
                .credentialsProvider(StaticCredentialsProvider.create(awsCreds))                    
                .build();