Home > other >  InvalidBucketName with Java AWS SDK 1.x using S3 Access points
InvalidBucketName with Java AWS SDK 1.x using S3 Access points

Time:12-06

I am trying to perform GetObject operation on a bucket via configured accesspoint through AWS SDK version 1.x (tried with 1.12.348 and 1.11.1004):

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

I have following code to execute the GetObject operation:

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);

According to the documentation bucketName can be:

The name of the bucket, or access point ARN, containing the desired object.

And..

When using this operation using an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using access points in the Amazon Simple Storage Service Developer Guide.

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

However this is throwing an error:

<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>

With the error it looks like it doesn't support the ARN formatted bucket name and complaining about special characters within the ARN accesspoint name.

PS: Within accesspoint value arn:aws:s3:<bucket-region>:<accountNumber>:accesspoint:<access-point-name>, actual values are replaces with placeholders between <>, so the error won't be related to these characters. This are presented here with placeholders for data protection purposes.

CodePudding user response:

pom.xml has another transitive dependency com.amazonaws:aws-java-sdk-bundle:jar:1.11.375:compile coming from following dependency:

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

aws-java-sdk-bundle was overriding most of the classes from the original aws-java-sdk-s3.

Swapping the position with hadoop-aws and aws-java-sdk-s3 resolved the issue! (pushing dependency aws-java-sdk-s3 before hadoop-aws)

  • Related