我需要从 S3 存储桶下载对象,我有以下信息可以访问 S3 存储桶。
访问密钥、秘密密钥和存储桶端点。没有区域名称。
我使用 minio 包访问存储桶,并且能够使用以下代码访问它:
public void getS3BucketObject() throws IOException, NoSuchAlgorithmException,
InvalidKeyException, ServerException, InsufficientDataException, InternalException, InvalidResponseException,
XmlParserException, ErrorResponseException {
//creating minioClient to access S3 bucket
minioClient =
MinioClient.builder()
.endpoint(s3BucketEndpoint)
.credentials(s3BucketAccessKey, s3BucketSecretKey)
.build();
//check for bucket existance
boolean found =
minioClient.bucketExists(BucketExistsArgs.builder().bucket(s3BucketName).build());
if (!found) {
System.out.println("Bucket doesn't exist ");
} else {
System.out.println("Bucket exists ");
}
}
但是,我确实需要使用 AWS SDK 而不是 minio,但我不确定,因为我没有区域信息,也不确定如何在配置设置中传递端点,尽管我在下面尝试过。
final BasicAWSCredentials credentials = new BasicAWSCredentials(s3BucketAccessKey, s3BucketSecretKey);
final AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials));
boolean found = s3client.doesBucketExistV2(s3BucketName);
if (found){
System.out.println("The bucket is available ");
}else {
System.out.println("The bucket doesn't exist");
}
答案 0 :(得分:0)
您是否在使用构建器创建 s3client 时尝试使用 withRegion(AWS_S3_REGION) 选项?
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withRegion("us-east-1")
.build();
AmazonS3ClientBuilder.defaultClient() fails to account for region?