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