Java Code Examples for

The following are Jave code examples for showing how to use getBucketLocation() of the class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: circus-train   File:   View Source Code Vote up 6 votes
private String regionForUri(AmazonS3 client, AmazonS3URI uri) {
  String bucketRegion = client.getBucketLocation(uri.getBucket());
  Region region = Region.fromValue(bucketRegion);

  // S3 doesn't have a US East 1 region, US East 1 is really the region
  // US Standard. US Standard places the data in either an east coast
  // or west coast data center geographically closest to you.
  // SigV4 requires you to mention a region while signing a request
  // and for the S3's US standard endpoints the value to be used is "us-east-1"
  // US West 1 has an endpoint and so is treated as a stand alone region,
  // US East 1 doesn't and so is bundled into US Standard
  if (region.equals(Region.US_Standard)) {
    bucketRegion = "us-east-1";
  } else {
    bucketRegion = region.toString();
  return bucketRegion;
Example 2
Project: dremio-oss   File:   View Source Code Vote up 5 votes
 * To reuse code for accountbased and external buckets
 * @param s3
 * @param parentConf
 * @param bucketName
 * @throws IOException
private FileSystem addBucketFSEntry(AmazonS3 s3, Configuration parentConf, String bucketName) throws AmazonS3Exception, IOException {
  final String bucketRegion = s3.getBucketLocation(bucketName);
  final String projectedBucketEndPoint = "s3." + bucketRegion + "";
  String regionEndPoint = projectedBucketEndPoint;
  try {
    Region region = Region.fromValue(bucketRegion);
    com.amazonaws.regions.Region awsRegion = region.toAWSRegion();
    if (awsRegion != null) {
      regionEndPoint = awsRegion.getServiceEndpoint("s3");
  } catch (IllegalArgumentException iae) {
    // try heuristic mapping if not found
    regionEndPoint = projectedBucketEndPoint;
    logger.warn("Unknown or unmapped region {} for bucket {}. Will use following fs.s3a.endpoint: {}",
      bucketRegion, bucketName, regionEndPoint);
  // it could be null because no mapping from Region to aws region or there is no such region is the map of endpoints
  // not sure if latter is possible
  if (regionEndPoint == null) {
    logger.error("Could not get AWSRegion for bucket {}. Will use following fs.s3a.endpoint: " + "{} ",
      bucketName, projectedBucketEndPoint);
  String location = S3_URI_SCHEMA + bucketName + "/";
  Configuration bucketConf = new Configuration(parentConf);
  bucketConf.set(ENDPOINT, (regionEndPoint != null) ? regionEndPoint : projectedBucketEndPoint);
  FileSystem.setDefaultUri(bucketConf, new Path(location).toUri());
  return FileSystem.get(bucketConf);