This commit is contained in:
avr
2024-09-13 13:17:04 +03:00
commit 4cbfed79da
11 changed files with 507 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package org.example.demos3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoS3Application {
public static void main(String[] args) {
SpringApplication.run(DemoS3Application.class, args);
}
}

View File

@ -0,0 +1,43 @@
package org.example.demos3.service;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.Bucket;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;
@Service
@Log4j2
public class MyService implements CommandLineRunner {
@Override
public void run(String... args) {
log.info("hello!");
try {
S3Client s3Client = S3Client.builder()
.credentialsProvider(() -> AwsBasicCredentials.create("accessKey1", "verySecretKey1"))
.region(Region.US_WEST_2)
.endpointOverride(new URI("http://localhost:8000"))
.forcePathStyle(true)
.build();
// s3Client.createBucket(CreateBucketRequest.builder().bucket("backetname-" + UUID.randomUUID()).build());
ListBucketsResponse listBucketsResponse = s3Client.listBuckets();
log.info(listBucketsResponse.buckets().stream().map(Bucket::name).toList().toString());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1 @@
spring.application.name=demoS3

View File

@ -0,0 +1,13 @@
package org.example.demos3;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DemoS3ApplicationTests {
@Test
void contextLoads() {
}
}