com.amazonaws.regions.Regions.fromName()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(178)

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

Regions.fromName介绍

[英]Returns a region enum corresponding to the given region name.
[中]返回与给定区域名称对应的区域枚举。

代码示例

代码示例来源:origin: blox/blox

/**
  * Setter for Jackson to deserialize Regions enum from string
  *
  * @param region
  */
 public void setRegion(String region) {
  this.region = Regions.fromName(region);
 }
}

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

/**
 * Returns the region configured for the default AWS SDK metric collector;
 * or null if the default is to be used.
 *
 * @throws IllegalArgumentException when using a region not included in
 * {@link Regions}
 *
 * @deprecated Use {@link #getRegionName()}
 */
public static Regions getRegion() throws IllegalArgumentException {
  return Regions.fromName(region.getName());
}

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

/**
 * Returns the the KMS region explicitly specified for the AWS KMS client
 * when such client is internally instantiated; or null if no explicit KMS
 * region is specified. This KMS region parameter is ignored when the AWS
 * KMS client of the S3 encryption client is explicitly passed in by the
 * users, instead of being implicitly created.
 *
 * @Deprecated This method is not forward compatible. Throws
 * IllegalArguementException when a new region is encountered.
 *
 * @use {@link #getAwsKmsRegion()} instead
 */
@Deprecated
public Regions getKmsRegion() {
  if (awskmsRegion == null) return null;
  return Regions.fromName(awskmsRegion.getName());
}

代码示例来源:origin: apache/incubator-gobblin

@VisibleForTesting
AWSSdkClient createAWSSdkClient() {
 return new AWSSdkClient(this.awsClusterSecurityManager,
   Region.getRegion(Regions.fromName(this.awsRegion)));
}

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

/**
 * Get the region
 */
private Region getRegion() {
  String regionName = fig.getPrimaryRegion();
  try {
    Regions regions = Regions.fromName(regionName);
    return Region.getRegion(regions);
  }
  catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("INVALID PRIMARY REGION FROM CONFIGURATION " + LegacyQueueFig.USERGRID_QUEUE_REGION_LOCAL + ": " + regionName, e);
  }
}

代码示例来源:origin: brianfrankcooper/YCSB

s3Client.setRegion(Region.getRegion(Regions.fromName(region)));
s3Client.setEndpoint(endPoint);
System.out.println("Connection successfully initialized");

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

private AmazonS3 getS3Client() throws Exception{
  this.bucketName = properties.getProperty( "usergrid.binary.bucketname" );
  if(bucketName == null){
    logger.error( "usergrid.binary.bucketname not properly set so amazon bucket is null" );
    throw new AwsPropertiesNotFoundException( "usergrid.binary.bucketname" );
  }
  final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider();
  AWSCredentials credentials = ugProvider.getCredentials();
  ClientConfiguration clientConfig = new ClientConfiguration();
  clientConfig.setProtocol(Protocol.HTTP);
  s3Client = new AmazonS3Client(credentials, clientConfig);
  if(regionName != null)
    s3Client.setRegion( Region.getRegion(Regions.fromName(regionName)) );
  return s3Client;
}

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

private URI getCreateBucketEndpoint(String requestRegion) {
  // Route to the default endpoint if they're not trying to specify a different one in the request.
  if(requestRegion == null || requestRegion.equals(clientRegion) || !clientOptions.isForceGlobalBucketAccessEnabled()) {
    return endpoint;
  }
  // If they enabled global bucket access and they're trying to create a bucket in a region different than the default
  // one specified when they created the client, it will probably fail because only us-east-1 (actually the global
  // endpoint) is capable of creating buckets outside of its region. Override the endpoint to which the request
  // is routed so that it will succeed.
  com.amazonaws.regions.Region targetRegion = com.amazonaws.regions.Region.getRegion(Regions.fromName(requestRegion));
  return new DefaultServiceEndpointBuilder(getEndpointPrefix(),
                       clientConfiguration.getProtocol().toString()).withRegion(targetRegion)
                                             .getServiceEndpoint();
}

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

Region region = null;
try {
  Regions regions = Regions.fromName(regionName);
  region = Region.getRegion(regions);
String strSqsRegion = queueArnEntry.getValue();
Regions sqsRegions = Regions.fromName( strSqsRegion );
Region sqsRegion = Region.getRegion( sqsRegions );
  Regions snsRegions = Regions.fromName( strSnsRegion );
  Region snsRegion = Region.getRegion( snsRegions );

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

protected void initializeRegionAndEndpoint(ProcessContext context) {
  // if the processor supports REGION, get the configured region.
  if (getSupportedPropertyDescriptors().contains(REGION)) {
    final String region = context.getProperty(REGION).getValue();
    if (region != null) {
      this.region = Region.getRegion(Regions.fromName(region));
      client.setRegion(this.region);
    } else {
      this.region = null;
    }
  }
  // if the endpoint override has been configured, set the endpoint.
  // (per Amazon docs this should only be configured at client creation)
  if (getSupportedPropertyDescriptors().contains(ENDPOINT_OVERRIDE)) {
    final String urlstr = StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue());
    if (!urlstr.isEmpty()) {
      getLogger().info("Overriding endpoint with {}", new Object[]{urlstr});
      if (urlstr.endsWith(".vpce.amazonaws.com")) {
        String region = parseRegionForVPCE(urlstr);
        this.client.setEndpoint(urlstr, this.client.getServiceName(), region);
      } else {
        this.client.setEndpoint(urlstr);
      }
    }
  }
}

代码示例来源:origin: pinterest/secor

client.setEndpoint(endpoint);
} else if (!region.isEmpty()) {
  client.setRegion(Region.getRegion(Regions.fromName(region)));

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
 * Returns the region configured for the default AWS SDK metric collector;
 * or null if the default is to be used.
 *
 * @throws IllegalArgumentException when using a region not included in
 * {@link Regions}
 *
 * @deprecated Use {@link #getRegionName()}
 */
public static Regions getRegion() throws IllegalArgumentException {
  return Regions.fromName(region.getName());
}

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

/**
 * Returns the region that the client is set to operate in.
 * Note: This may be different from the region the client uses in its signature.
 * @return the region that the client is set to operate in
 */
public Regions getRegions() {
  synchronized (this) {
    return Regions.fromName(this.region.getName());
  }
}

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

@Override
protected GenericApiGatewayClient createClient(ProcessContext context,
                        AWSCredentialsProvider awsCredentialsProvider,
                        ClientConfiguration clientConfiguration) {
  GenericApiGatewayClientBuilder builder = new GenericApiGatewayClientBuilder()
    .withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration)
    .withEndpoint(context.getProperty(PROP_AWS_GATEWAY_API_ENDPOINT).getValue()).withRegion(
      Region.getRegion(
        Regions.fromName(context.getProperty(PROP_AWS_GATEWAY_API_REGION).getValue())));
  if (context.getProperty(PROP_AWS_API_KEY).isSet()) {
    builder = builder.withApiKey(context.getProperty(PROP_AWS_API_KEY).evaluateAttributeExpressions().getValue());
  }
  if (providedClient != null) {
    builder = builder.withHttpClient(providedClient);
  }
  return builder.build();
}

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

private static Regions getRegions(AWSConfiguration awsConfiguration) {
  try {
    final JSONObject ccpConfig = awsConfiguration.optJsonObject("CredentialsProvider")
        .optJSONObject("CognitoIdentity")
        .getJSONObject(awsConfiguration.getConfiguration());
    return Regions.fromName(ccpConfig.getString("Region"));
  } catch (Exception e) {
    throw new IllegalArgumentException("Failed to read CognitoIdentity please check your setup or awsconfiguration.json file", e);
  }
}

代码示例来源:origin: aws-samples/aws-big-data-blog

public BatchedClickEventsToKinesis(BlockingQueue<ClickEvent> inputQueue) {
  super(inputQueue);
  kinesis = new AmazonKinesisClient().withRegion(
      Regions.fromName(REGION));
  entries = new ArrayList<>();
  dataSize = 0;
}

代码示例来源:origin: aws-samples/aws-big-data-blog

protected MetricsEmittingBasicClickEventsToKinesis(
    BlockingQueue<ClickEvent> inputQueue) {
  super(inputQueue);
  kinesis = new AmazonKinesisClient().withRegion(
      Regions.fromName(REGION));
  cw = new AmazonCloudWatchClient().withRegion(Regions.fromName(REGION));
}

代码示例来源:origin: aws-samples/aws-big-data-blog

public BasicClickEventsToKinesis(BlockingQueue<ClickEvent> inputQueue) {
  super(inputQueue);
  kinesis = new AmazonKinesisClient().withRegion(
      Regions.fromName(REGION));
}

代码示例来源:origin: aws-samples/aws-big-data-blog

public AggregatingClickEventsToKinesis(
    BlockingQueue<ClickEvent> inputQueue) {
  super(inputQueue);
  kinesis = new AmazonKinesisClient().withRegion(
      Regions.fromName(REGION));
  reset();
}

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

@Test
  public void testFromName() {
    final Regions usEast1 = Regions.fromName("us-east-1");
    assertEquals(usEast1, Regions.US_EAST_1);
    final Regions cn1 = Regions.fromName("cn-north-1");
    assertEquals(cn1, Regions.CN_NORTH_1);
    final Regions govCloud = Regions.fromName("us-gov-west-1");
    assertEquals(govCloud, Regions.GovCloud);
    assertEquals(usEast1.getName(), "us-east-1");
  }
}

相关文章