com.amazonaws.services.s3.model.Region类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中com.amazonaws.services.s3.model.Region类的一些代码示例,展示了Region类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Region类的具体详情如下:
包路径:com.amazonaws.services.s3.model.Region
类名称:Region

Region介绍

[英]Specifies constants that define Amazon S3 Regions.

Amazon S3 Regions allow the user to choose the geographical region where Amazon S3 will store the buckets the user creates. Choose a Amazon S3 Region to optimize latency, minimize costs, or address regulatory requirements.

Objects stored in a Amazon S3 Region never leave that region unless explicitly transferred to another region.

In Amazon S3, all the regions provides read-after-write consistency for PUTS of new objects in Amazon S3 buckets and eventual consistency for overwrite PUTS and DELETES.
[中]指定定义Amazon S3区域的常量。
Amazon S3区域允许用户选择Amazon S3存储用户创建的存储桶的地理区域。选择Amazon S3区域以优化延迟、最小化成本或满足监管要求。
存储在Amazon S3区域中的对象永远不会离开该区域,除非显式地转移到另一个区域。
在Amazon S3中,所有区域都为Amazon S3存储桶中新对象的PUT提供了读写一致性,并最终为覆盖PUT和删除提供了一致性。

代码示例

代码示例来源:origin: aws/aws-sdk-java

@Override
public synchronized Region getRegion() {
  String authority = super.endpoint.getAuthority();
  if (Constants.S3_HOSTNAME.equals(authority)) {
    return Region.US_Standard;
  } else {
    Matcher m = Region.S3_REGIONAL_ENDPOINT_PATTERN.matcher(authority);
    if (m.matches()) {
      return Region.fromValue(m.group(1));
    } else {
      throw new IllegalStateException(
        "S3 client with invalid S3 endpoint configured: " + authority);
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

private ServiceEndpointBuilder getBuilder(URI endpoint, String protocol, boolean useDefaultBuilder) {
  if(clientOptions.isDualstackEnabled() && !clientOptions.isAccelerateModeEnabled()) {
    return new DualstackEndpointBuilder(getServiceNameIntern(), protocol, getRegion().toAWSRegion());
  } else {
    if(useDefaultBuilder) {
      return new DefaultServiceEndpointBuilder(getServiceName(), protocol);
    } else {
      return new IdentityEndpointBuilder(endpoint);
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public Bucket createBucket(CreateBucketRequest createBucketRequest)
    throws SdkClientException, AmazonServiceException {
  createBucketRequest = beforeClientExecution(createBucketRequest);
  rejectNull(createBucketRequest,
        "The CreateBucketRequest parameter must be specified when creating a bucket");
  rejectNull(bucketName, "The bucket name parameter must be specified when creating a bucket");
  bucketName = bucketName.trim();
  if (requestRegion != null && !StringUtils.upperCase(requestRegion).equals(Region.US_Standard.toString())) {
    XmlWriter xml = new XmlWriter();
    xml.start("CreateBucketConfiguration", "xmlns", Constants.XML_NAMESPACE);

代码示例来源:origin: apache/jackrabbit

|| StringUtils.isNullOrEmpty(secretKey)) {
  LOG.info("Configuring Amazon Client from environment");
  s3service = new AmazonS3Client(getClientConfiguration(prop));
} else {
  LOG.info("Configuring Amazon Client from property file.");
  AWSCredentials credentials = new BasicAWSCredentials(accessKey,
    secretKey);
  s3service = new AmazonS3Client(credentials,
    getClientConfiguration(prop));
  } else if (Region.EU_Ireland.toString().equals(region)) {
    endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
  } else {
s3service.setEndpoint(endpoint);
LOG.info("S3 service endpoint [{}] ", endpoint);
return s3service;

代码示例来源:origin: aws-amplify/aws-sdk-android

client = new AmazonS3Client(credentialProvider);
} else {
  client = new AmazonS3Client(credentials);
client.setRegion(s3region.toAWSRegion());
final AmazonS3Client prev = clientsByRegion.putIfAbsent(s3region, client);
return prev == null ? client : prev;

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-aws-ext

com.amazonaws.regions.Region ec2Region = Regions.getCurrentRegion();
  if (ec2Region != null) {
    s3Region = Region.fromValue(ec2Region.getName());
  } else {
    throw new AmazonClientException(
  if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) {
    s3Region = Region.US_Standard;
  } else if (Region.EU_Ireland.toString().equals(region)) {
    s3Region = Region.EU_Ireland;
  } else {
    s3Region = Region.fromValue(region);
if (!s3service.doesBucketExist(bucket)) {
  s3service.createBucket(bucket, s3Region);
  LOG.info("Created bucket [{}] in [{}] ", bucket, region);
} else {

代码示例来源:origin: dremio/dremio-oss

@Override
 public FileSystem create() throws IOException {
  final String bucketRegion = s3.getBucketLocation(bucketName);
  final String projectedBucketEndPoint = "s3." + bucketRegion + ".amazonaws.com";
  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 + "/";
  final Configuration bucketConf = new Configuration(parentConf);
  bucketConf.set(ENDPOINT, (regionEndPoint != null) ? regionEndPoint : projectedBucketEndPoint);
  FileSystem.setDefaultUri(bucketConf, new Path(location).toUri());
  return FileSystem.get(bucketConf);
 }
});

代码示例来源:origin: HotelsDotCom/circus-train

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;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testRegionEnumeration() {
  assertEquals(Region.EU_Ireland, Region.fromValue(Region.EU_Ireland.toString()));
  assertEquals(Region.US_Standard, Region.fromValue(Region.US_Standard.toString()));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

final Request<CreateBucketRequest> request = createRequest(bucketName, null, createBucketRequest,
    HttpMethodName.PUT);
  addAclHeaders(request, createBucketRequest.getAccessControlList());
} else if (createBucketRequest.getCannedAcl() != null) {
  request.addHeader(Headers.S3_CANNED_ACL, createBucketRequest.getCannedAcl().toString());
if (region != null && !StringUtils.upperCase(region).equals(Region.US_Standard.toString())) {
  final XmlWriter xml = new XmlWriter();
  xml.start("CreateBucketConfiguration", "xmlns", Constants.XML_NAMESPACE);
invoke(request, voidResponseHandler, bucketName, null);

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns a client for the requested region, or throws an exception when
 * unable.
 *
 * @param region
 *            The region the returned {@link AmazonS3} will be
 *            configured to use.
 * @return A client for the given region from the cache, either instantiated
 *         automatically from the provided {@link AWSCredentials} or
 *         provided with {@link #useClient(AmazonS3)}.
 * @throws IllegalArgumentException
 *             When a region is requested that has not been provided to the
 *             cache with {@link #useClient(AmazonS3)}, and the cache
 *             has no {@link AWSCredentials} with which a client may be
 *             instantiated.
 */
public AmazonS3 getClient(Region region) {
  if (region == null) {
    throw new IllegalArgumentException("S3 region must be specified");
  }
  return getClient(region.toAWSRegion().getName());
}

代码示例来源:origin: aws/aws-sdk-java

private static String convertRegionToString(Region region, String bucketName) {
  String regionAsString;
  if (region == null) {
    if (BucketNameUtils.isDNSBucketName(bucketName)) {
      regionAsString = Region.US_Standard.getFirstRegionId();
    } else {
      throw new IllegalArgumentException("Region must be specified for bucket that cannot be addressed using virtual host style");
    }
  } else {
    regionAsString = region.getFirstRegionId();
  }
  return regionAsString;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Constructs a new {@link CreateBucketRequest},
 * ready to be executed to create the
 * specified bucket in the specified region.
 *
 * @param bucketName
 *            The name of the Amazon S3 bucket to create.
 * @param region
 *            The region in which to create this bucket. This must match the
 *            region of the endpoint the client is configured against unless
 *            the client is configured against the US Standard endpoint
 *            (s3.amazonaws.com).
 *
 * @see CreateBucketRequest#CreateBucketRequest(String)
 * @see CreateBucketRequest#CreateBucketRequest(String, String)
 */
public CreateBucketRequest(String bucketName, Region region) {
  this(bucketName, region.toString());
}

代码示例来源:origin: takipi/aws-s3-speed

for (Region region : Region.values())
    if (region.toString() != null) {
      regionName = region.toString();
    } else {
      regionName = "us-east-1";

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns the first region id or null for {@link #US_Standard}.
 */
public String getFirstRegionId() {
  return getFirstRegionId0();
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Returns the Amazon S3 Region enumeration value representing the specified Amazon
 * S3 Region ID string. If specified string doesn't map to a known Amazon S3
 * Region, then an <code>IllegalArgumentException</code> is thrown.
 *
 * @param s3RegionId
 *            The Amazon S3 region ID string.
 *
 * @return The Amazon S3 Region enumeration value representing the specified Amazon
 *         S3 Region ID.
 *
 * @throws IllegalArgumentException
 *             If the specified value does not map to one of the known
 *             Amazon S3 regions.
 */
public static Region fromValue(final String s3RegionId) throws IllegalArgumentException
{
  if (s3RegionId == null || s3RegionId.equals("US") || s3RegionId.equals("us-east-1")) {
    return Region.US_Standard;
  }
  for (Region region : Region.values()) {
    List<String> regionIds = region.regionIds;
    if (regionIds != null && regionIds.contains(s3RegionId))
      return region;
  }
  throw new IllegalArgumentException(
      "Cannot create enum from " + s3RegionId + " value!");
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-aws-ext

|| StringUtils.isNullOrEmpty(secretKey)) {
  LOG.info("Configuring Amazon Client from environment");
  s3service = new AmazonS3Client(getClientConfiguration(prop));
} else {
  LOG.info("Configuring Amazon Client from property file.");
  AWSCredentials credentials = new BasicAWSCredentials(accessKey,
    secretKey);
  s3service = new AmazonS3Client(credentials,
    getClientConfiguration(prop));
  } else if (Region.EU_Ireland.toString().equals(region)) {
    endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
  } else {
s3service.setEndpoint(endpoint);
LOG.info("S3 service endpoint [{}] ", endpoint);
return s3service;

代码示例来源:origin: apache/jackrabbit

com.amazonaws.regions.Region ec2Region = Regions.getCurrentRegion();
  if (ec2Region != null) {
    s3Region = Region.fromValue(ec2Region.getName());
  } else {
    throw new AmazonClientException(
  if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) {
    s3Region = Region.US_Standard;
  } else if (Region.EU_Ireland.toString().equals(region)) {
    s3Region = Region.EU_Ireland;
  } else {
    s3Region = Region.fromValue(region);
if (!s3service.doesBucketExist(bucket)) {
  s3service.createBucket(bucket, s3Region);
  LOG.info("Created bucket [{}] in [{}] ", bucket, region);
} else {

代码示例来源:origin: org.duracloud/s3storageprovider

public static AmazonS3Client getAmazonS3Client(String accessKey,
                        String secretKey,
                        Map<String, String> options) {
  AmazonS3Client client = s3Clients.get(key(accessKey, secretKey));
  if (null == client) {
    Region region = null;
    if (options != null && options.get(StorageAccount.OPTS.AWS_REGION.name()) != null) {
      region = com.amazonaws.services.s3.model.Region.fromValue(
        options.get(StorageAccount.OPTS.AWS_REGION.name())).toAWSRegion();
    }
    client = newS3Client(accessKey, secretKey, region);
    s3Clients.put(key(accessKey, secretKey), client);
  }
  return client;
}

代码示例来源:origin: com.hotels/circus-train-s3-s3-copier

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;
}

相关文章