I\'m using AWS Java SDK provided by Amazon to interact with the S3 service.
It seems that by default, the SDK uses virtual-host-style for buckets (i.e. buckets are r
The method withPathStyleAccess has been deprecated. Please use the following instead:
AmazonS3 s3client = AmazonS3Client.builder()
.withCredentials((new AWSStaticCredentialsProvider(credentials)))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("host", "region"))
.withPathStyleAccessEnabled(true)
.build();
Deprecated method:
This is now possible, I'm not sure when it was introduced, but it's available in at least the 1.7.8 version of the Java AWS SDK.
Just call setClientOptions on your AmazonS3 instance:
AmazonS3 client = new AmazonS3Client(credentials);
client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
For SDK v2 you can you enable path style by doing this:
public S3Client build() {
final S3Configuration config = S3Configuration.builder()
.pathStyleAccessEnabled(true)
.build();
return S3Client.builder()
.serviceConfiguration(config)
// other set up
.build();
}
Amazon wass planning to deprecate path style access from Sept 2020, but this deprecation has been postponed: https://forums.aws.amazon.com/ann.jspa?annID=6776
There's no way to force V1 (path-style) bucket addressing using the Java SDK. The only exception is when your bucket name isn't DNS addressable, in which case the SDK will automatically use V1 addressing. This happens, e.g., when your bucket name contains a period (which is discouraged for this reason).
If you want this functionality, you'll have to modify the AmazonS3Client
class to allow it.
https://github.com/amazonwebservices/aws-sdk-for-java/
However, I'm not sure I believe your claim that you "need" to use V1 bucket addressing. The SDK already handles all cases where V1 addressing is necessary -- or if you have found a case where it doesn't, please let us know in the forums.
https://forums.aws.amazon.com/forum.jspa?forumID=70