Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awsdocs
GitHub Repository: awsdocs/amazon-s3-developer-guide
Path: blob/master/code_examples/java_examples/S3Examples/DualStackEndpoints.java
4084 views
1
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
// SPDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-s3-developer-guide/blob/master/LICENSE-SAMPLECODE.)
3
4
import com.amazonaws.AmazonServiceException;
5
import com.amazonaws.SdkClientException;
6
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
7
import com.amazonaws.services.s3.AmazonS3;
8
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
9
10
public class DualStackEndpoints {
11
12
public static void main(String[] args) {
13
String clientRegion = "*** Client region ***";
14
String bucketName = "*** Bucket name ***";
15
16
try {
17
// Create an Amazon S3 client with dual-stack endpoints enabled.
18
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
19
.withCredentials(new ProfileCredentialsProvider())
20
.withRegion(clientRegion)
21
.withDualstackEnabled(true)
22
.build();
23
24
s3Client.listObjects(bucketName);
25
}
26
catch(AmazonServiceException e) {
27
// The call was transmitted successfully, but Amazon S3 couldn't process
28
// it, so it returned an error response.
29
e.printStackTrace();
30
}
31
catch(SdkClientException e) {
32
// Amazon S3 couldn't be contacted for a response, or the client
33
// couldn't parse the response from Amazon S3.
34
e.printStackTrace();
35
}
36
}
37
}
38
39