List of usage examples for com.amazonaws.services.s3 AmazonS3 getRegion
Region getRegion();
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
/** * ?/*from ww w.ja va 2s . c o m*/ * * @param bucketName * @return s3client * @throws StoreException * @throws Exception */ private AmazonS3 getS3Client(String bucketName) throws StoreException { logger.debug("get S3 Client start."); // ? AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider(); // ClientConfiguration clientConfig = new ClientConfiguration() // .withProtocol(Protocol.HTTPS) // Proxy // .withProxyHost("proxyHost") // .withProxyPort(80) // .withProxyUsername("proxyUsername") // .withProxyPassword("proxyPassword") .withConnectionTimeout(10000); // ? AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(provider) .withClientConfiguration(clientConfig).withRegion(DEFAULT_REGION) .withForceGlobalBucketAccessEnabled(true).build(); logger.debug("Region={}", s3client.getRegion()); try { // ?? if (!CommonUtils.isNullOrEmpty(bucketName) && !(s3client.doesBucketExistV2(bucketName))) { s3client.createBucket(new CreateBucketRequest(bucketName, DEFAULT_REGION.getName())); } // Get location. String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName)); logger.info("bucket location={}", bucketLocation); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_CONFLICT, ErrorClassification.BS0003, ace, "?"); } logger.info("get S3 Client end."); return s3client; }