olá, galera!
Estou tentando simular o Amazon S3 localmente com o Ninja S3 (s3ninja.net/). Implementando sessa forma deu certo:
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
public void test01() {
final String ID = "AKIAIOSFODNN7EXAMPLE";
final String KEY ="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
final String NINJA_URL = "http://localhost:9444/s3";
AWSCredentials credentials = new BasicAWSCredentials(ID, KEY);
AmazonS3 s3client = new AmazonS3Client(credentials, new ClientConfiguration());
s3client.setEndpoint(NINJA_URL);
//lista os buckets
System.out.println(s3client.listBuckets());
}
Porém atualizando para a ultima versão do SDK da AmazonAWS, que é o 1.11.222, a chamada new AmazonS3Client() está depreciada. Olhando a API na última versão, tentei adequar o código dessa forma:
public void test01() {
final String ID = "AKIAIOSFODNN7EXAMPLE";
final String KEY ="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
final String NINJA_URL = "http://localhost:9444/s3";
BasicAWSCredentials creds = new BasicAWSCredentials(ID, KEY);
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).build(); // com.amazonaws.SdkClientException aqui
s3client.setEndpoint(NINJA_URL);
System.out.println(s3client.listBuckets());
}
Mas na linha estou obtendo a execeção:
com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit
region in the builder or setup environment to supply a region.
at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371)
at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at main.Main01.test01(Main01.java:37)
at main.Main01.main(Main01.java:27)
Alguém sabe como poderia resolver esse erro?
obrigado