List of usage examples for com.amazonaws.services.s3 AmazonS3 getBucketLocation
public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest) throws SdkClientException, AmazonServiceException;
Gets the geographical region where Amazon S3 stores the specified bucket.
From source file:com.dustindoloff.s3websitedeploy.Main.java
License:Apache License
private static Region getBucketRegion(final AmazonS3 s3Client, final String bucket) { try {//from www . j av a 2 s. c om return Region.getRegion(Regions.fromName(s3Client.getBucketLocation(bucket))); } catch (final AmazonClientException | IllegalArgumentException e) { return null; } }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
/** * ?/*ww w .ja v a 2 s . com*/ * * @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; }
From source file:com.images3.data.impl.ImageContentAccessImplS3.java
License:Apache License
@Override public boolean testBucketAccessibility(AmazonS3Bucket bucket) { try {//from w ww .j av a 2s . c om AmazonS3 client = clients.getClient(bucket); client.getBucketLocation(bucket.getName()); } catch (AmazonClientException e) { return false; } return true; }
From source file:io.vgs.tools.aws.maven.SimpleStorageServiceWagon.java
License:Apache License
@Override protected void connectToRepository(Repository repository, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider) throws AuthenticationException { if (this.amazonS3 == null) { AuthenticationInfoAWSCredentialsProviderChain credentialsProvider = new AuthenticationInfoAWSCredentialsProviderChain( authenticationInfo);/*from w w w.j a va2 s . co m*/ ClientConfiguration clientConfiguration = S3Utils.getClientConfiguration(proxyInfoProvider); this.bucketName = S3Utils.getBucketName(repository); this.baseDirectory = S3Utils.getBaseDirectory(repository); AmazonS3 noRegionAmazonS3 = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider) .withClientConfiguration(clientConfiguration).build(); this.amazonS3 = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider) .withClientConfiguration(clientConfiguration) .withRegion(noRegionAmazonS3.getBucketLocation(this.bucketName)).build(); } }
From source file:jp.classmethod.aws.gradle.s3.CreateBucketTask.java
License:Apache License
private boolean exists(AmazonS3 s3) { // to enable conventionMappings feature String bucketName = getBucketName(); try {/* w ww.ja va2 s . co m*/ s3.getBucketLocation(bucketName); return true; } catch (AmazonClientException e) { return false; } }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Inject public AmazonS3Storage(Configuration configuration) { bucketName = configuration.getString("storage.s3.bucket", "thunderbit"); String accessKey = configuration.getString("storage.s3.accesskey"); String secretKey = configuration.getString("storage.s3.secretkey"); credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3 amazonS3 = new AmazonS3Client(credentials); if (configuration.getBoolean("storage.s3.createBucket", true)) { try {/*from w w w . jav a2s . co m*/ if (!(amazonS3.doesBucketExist(bucketName))) { amazonS3.createBucket(new CreateBucketRequest(bucketName)); } String bucketLocation = amazonS3.getBucketLocation(new GetBucketLocationRequest(bucketName)); logger.info("Amazon S3 bucket created at " + bucketLocation); } catch (AmazonServiceException ase) { logAmazonServiceException(ase); } catch (AmazonClientException ace) { logAmazonClientException(ace); } } }