AWSCredentialsProvider provider;
if (accessKey != null && secretKey != null) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
provider = new StaticCredentialsProvider(credentials);
} else {
provider = new DefaultAWSCredentialsProviderChain();
}
return new AmazonS3Client(provider);
}