InvalidBucketName with Java AWS SDKx使用S3接入点



我试图通过AWS SDK版本1通过配置的accesspoint在桶上执行GetObject操作。X(试过1.12.348和1.11.1004):

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.348</version>
</dependency>

我有以下代码来执行GetObject操作:

AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withRegion(awsRegion).build();
String bucketName= "arn:aws:s3:<bucket-region>:<accountNumber>:accesspoint:<access-point-name>";
String key = "bucket/path/filename.txt";
File to = // a file;
amazonS3.getObject(new GetObjectRequest(bucketName, key), to);

根据文档,bucketName可以是:

包含所需对象的桶名或接入点ARN。

和.

当通过Amazon Web Services sdk使用接入点使用此操作时,您可以提供接入点ARN来代替桶名。有关接入点arn的更多信息,请参见《Amazon Simple Storage Service Developer Guide》中的使用接入点。

https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html

但是这会抛出一个错误:

<Error><Code>InvalidBucketName</Code><Message>The specified bucket is not valid.</Message><BucketName>arn:aws:s3:<bucket-region>:<accountNumber>:accesspoint:<access-point-name></BucketName><RequestId>**********</RequestId><HostId>*******************</HostId></Error>

这个错误看起来不支持ARN格式的桶名,并抱怨在ARN访问点名称中有特殊字符。

PS:在accesspoint值arn:aws:s3:<bucket-region>:<accountNumber>:accesspoint:<access-point-name>中,实际值被<>之间的占位符替换,因此错误与这些字符无关。这里用占位符表示,以保护数据。

pom.xml有另一个传递依赖com.amazonaws:aws-java-sdk-bundle:jar:1.11.375:compile来自以下依赖:

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-aws</artifactId>
<version>${hadoop.version}</version>
</dependency>

aws-java-sdk-bundle覆盖了原aws-java-sdk-s3的大部分类。

hadoop-awsaws-java-sdk-s3交换位置解决了这个问题!(将依赖项aws-java-sdk-s3推到hadoop-aws之前)

最新更新