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

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

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

Regions.getCurrentRegion介绍

[英]Returns a Region object representing the region the application is running in, when running in EC2. If this method is called from a non-EC2 environment, it will return null.
[中]在EC2中运行时,返回表示应用程序运行所在区域的Region对象。如果从非EC2环境调用此方法,它将返回null。

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

com.amazonaws.regions.Region r = Regions.getCurrentRegion();

代码示例来源:origin: opentripplanner/OpenTripPlanner

/** create a task statistics store for the given queue name */
public SQSTaskStatisticsStore(String queueName) {
  Region current = Regions.getCurrentRegion();
  if (current != null) {
    LOG.info("Assuming statistics queue is in region {}", current);
    sqs.setEndpoint("sqs." + current.toString() + ".amazonaws.com");
  }
  try {
    queueUrl = sqs.getQueueUrl(queueName).getQueueUrl();
  } catch (Exception e) {
    LOG.error("Unable to initialize statistics store", e);
  }
  LOG.info("Sending statistics to SQS queue {}", queueName);
}

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

/**
 * Configuring the CloudWatch client.
 *
 * Credentials are loaded from the Amazon EC2 Instance Metadata Service
 */
private AmazonCloudWatchClient createCloudWatchClient() {
  AmazonCloudWatchClient cloudWatchClient = new AmazonCloudWatchClient(new InstanceProfileCredentialsProvider());
  cloudWatchClient.setRegion(checkNotNull(Regions.getCurrentRegion(), "Problems getting AWS metadata"));
  return cloudWatchClient;
}

代码示例来源:origin: prestodb/presto

private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config)
{
  ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections());
  AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard()
      .withClientConfiguration(clientConfig);
  if (config.getGlueRegion().isPresent()) {
    asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
  }
  else if (config.getPinGlueClientToCurrentRegion()) {
    Region currentRegion = Regions.getCurrentRegion();
    if (currentRegion != null) {
      asyncGlueClientBuilder.setRegion(currentRegion.getName());
    }
  }
  return asyncGlueClientBuilder.build();
}

代码示例来源:origin: prestodb/presto

Region region = Regions.getCurrentRegion();
if (region != null) {
  clientBuilder.withRegion(region.getName());

代码示例来源:origin: prestodb/presto

Region region = Regions.getCurrentRegion();
if (region != null) {
  clientBuilder = clientBuilder.withRegion(region.getName());

代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-aws

@Override
 public String getRegion() throws SdkClientException {
  return Regions.getCurrentRegion().getName();
 }
}

代码示例来源:origin: bazaarvoice/emodb

@Provides
@Singleton
protected Region provideAmazonRegion() {
  return Objects.firstNonNull(Regions.getCurrentRegion(), Region.getRegion(Regions.US_EAST_1));
}

代码示例来源:origin: VanRoy/spring-data-jest

@ConditionalOnMissingBean(name = "elasticsearchJestAwsRegion")
@Bean(name = "elasticsearchJestAwsRegion")
public String regionFromEC2() {
  // Try to determine current region ( work on EC2 instance )
  Region region = Regions.getCurrentRegion();
  if (region != null) {
    return region.getName();
  }
  // Nothing else , back to default
  return Regions.DEFAULT_REGION.getName();
}

代码示例来源:origin: awslabs/dynamodb-cross-region-library

CLOUDWATCH.get().setRegion(Regions.getCurrentRegion() == null ? Region.getRegion(Regions.US_EAST_1) : Regions.getCurrentRegion());

代码示例来源:origin: awslabs/dynamodb-cross-region-library

/**
 * Constructor with default CloudWatch client and default DynamoDBAsync.
 *
 * @param configuration
 *            The configuration for this emitter.
 * @deprecated Deprecated by {@link #DynamoDBReplicationEmitter(DynamoDBStreamsConnectorConfiguration, AmazonDynamoDBAsync, AmazonCloudWatchAsync)}
 */
@Deprecated
public DynamoDBReplicationEmitter(final DynamoDBStreamsConnectorConfiguration configuration) {
  this(configuration.APP_NAME, configuration.DYNAMODB_ENDPOINT, configuration.REGION_NAME, configuration.DYNAMODB_DATA_TABLE_NAME,
    (AmazonCloudWatchAsync) new AmazonCloudWatchAsyncClient(new DefaultAWSCredentialsProviderChain(), Executors.newFixedThreadPool(MAX_THREADS)).withRegion(Regions.getCurrentRegion() == null ? Region.getRegion(Regions.US_EAST_1) : Regions.getCurrentRegion()), new DefaultAWSCredentialsProviderChain());
}

代码示例来源:origin: org.jmxtrans/jmxtrans-output-cloudwatch

/**
 * Configuring the CloudWatch client.
 *
 * Credentials are loaded from the Amazon EC2 Instance Metadata Service
 */
private AmazonCloudWatchClient createCloudWatchClient() {
  AmazonCloudWatchClient cloudWatchClient = new AmazonCloudWatchClient(new InstanceProfileCredentialsProvider());
  cloudWatchClient.setRegion(checkNotNull(Regions.getCurrentRegion(), "Problems getting AWS metadata"));
  return cloudWatchClient;
}

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

private static Region getStartingRegion(final String keyArn) {
  final String region = parseRegionfromKeyArn(keyArn);
  if (region != null) {
    return RegionUtils.getRegion(region);
  }
  final Region currentRegion = Regions.getCurrentRegion();
  if (currentRegion != null) {
    return currentRegion;
  }
  return Region.getRegion(Regions.DEFAULT_REGION);
}

代码示例来源:origin: org.apache.jackrabbit/oak-blob-cloud

} else {
  if (StringUtils.isNullOrEmpty(region)) {
    com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion();
    if (s3Region != null) {
      region = s3Region.getName();

代码示例来源:origin: prestosql/presto

private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config)
{
  ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections());
  AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard()
      .withClientConfiguration(clientConfig);
  if (config.getGlueRegion().isPresent()) {
    asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
  }
  else if (config.getPinGlueClientToCurrentRegion()) {
    Region currentRegion = Regions.getCurrentRegion();
    if (currentRegion != null) {
      asyncGlueClientBuilder.setRegion(currentRegion.getName());
    }
  }
  return asyncGlueClientBuilder.build();
}

代码示例来源:origin: org.apereo.cas/cas-server-support-aws

val currentRegion = Regions.getCurrentRegion();
if (currentRegion != null && StringUtils.isBlank(region)) {
  region = currentRegion.getName();

代码示例来源:origin: guardian/kinesis-logback-appender

/**
 * Determine region. If not specified tries to determine region from where the
 * application is running or fall back to the default.
 * 
 * @return Region to configure the client
 */
private Region findRegion() {
 boolean regionProvided = !Validator.isBlank(this.region);
 if(!regionProvided) {
  // Determine region from where application is running, or fall back to default region
  Region currentRegion = Regions.getCurrentRegion();
  if(currentRegion != null) {
   return currentRegion;
  }
  return Region.getRegion(Regions.fromName(AppenderConstants.DEFAULT_REGION));
 }
 return Region.getRegion(Regions.fromName(this.region));
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

private static Region getRegion(EnvVars vars) {
    if (vars.get(AWS_DEFAULT_REGION) != null) {
      return Region.getRegion(Regions.fromName(vars.get(AWS_DEFAULT_REGION)));
    }
    if (vars.get(AWS_REGION) != null) {
      return Region.getRegion(Regions.fromName(vars.get(AWS_REGION)));
    }
    if (System.getenv(AWS_DEFAULT_REGION) != null) {
      return Region.getRegion(Regions.fromName(System.getenv(AWS_DEFAULT_REGION)));
    }
    if (System.getenv(AWS_REGION) != null) {
      return Region.getRegion(Regions.fromName(System.getenv(AWS_REGION)));
    }
    Region currentRegion = Regions.getCurrentRegion();
    if (currentRegion != null) {
      return currentRegion;
    }
    return Region.getRegion(Regions.DEFAULT_REGION);
  }
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-hive

private AmazonS3Client createAmazonS3Client(URI uri, Configuration hadoopConfig, ClientConfiguration clientConfig)
{
  AWSCredentialsProvider credentials = getAwsCredentialsProvider(uri, hadoopConfig);
  EncryptionMaterialsProvider emp = createEncryptionMaterialsProvider(hadoopConfig);
  AmazonS3Client client;
  if (emp != null) {
    client = new AmazonS3EncryptionClient(credentials, emp, clientConfig, new CryptoConfiguration(), METRIC_COLLECTOR);
  }
  else {
    client = new AmazonS3Client(credentials, clientConfig, METRIC_COLLECTOR);
  }
  // use local region when running inside of EC2
  if (pinS3ClientToCurrentRegion) {
    Region region = Regions.getCurrentRegion();
    if (region != null) {
      client.setRegion(region);
    }
  }
  return client;
}

代码示例来源:origin: prestosql/presto

Region region = Regions.getCurrentRegion();
if (region != null) {
  clientBuilder = clientBuilder.withRegion(region.getName());

相关文章