List of usage examples for com.amazonaws.util AwsHostNameUtils parseRegion
public static String parseRegion(final String host, final String serviceHint)
From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java
License:Open Source License
@VisibleForTesting static AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(final Optional<String> endpoint, final String signingRegion) { Preconditions.checkArgument(endpoint != null, "must provide an optional endpoint and not null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(signingRegion), "must provide a signing region"); final String expectedServiceEndpoint = "https://" + Region.getRegion(Regions.fromName(signingRegion)) .getServiceEndpoint(AmazonDynamoDB.ENDPOINT_PREFIX); if (endpoint.isPresent() && !Strings.isNullOrEmpty(endpoint.get())) { final String regionParsedFromEndpoint = AwsHostNameUtils.parseRegion(endpoint.get(), AmazonDynamoDB.ENDPOINT_PREFIX); Preconditions.checkArgument(/*from w w w.ja v a 2 s. c o m*/ regionParsedFromEndpoint == null || signingRegion.equals(regionParsedFromEndpoint)); return new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signingRegion); } else { //Regions.fromName will throw IllegalArgumentException if signingRegion is not valid. return new AwsClientBuilder.EndpointConfiguration(expectedServiceEndpoint, signingRegion); } }
From source file:org.apache.druid.indexing.kinesis.KinesisRecordSupplier.java
License:Apache License
public static AmazonKinesis getAmazonKinesisClient(String endpoint, AWSCredentialsConfig awsCredentialsConfig, String awsAssumedRoleArn, String awsExternalId) { AWSCredentialsProvider awsCredentialsProvider = AWSCredentialsUtils .defaultAWSCredentialsProviderChain(awsCredentialsConfig); if (awsAssumedRoleArn != null) { log.info("Assuming role [%s] with externalId [%s]", awsAssumedRoleArn, awsExternalId); STSAssumeRoleSessionCredentialsProvider.Builder builder = new STSAssumeRoleSessionCredentialsProvider.Builder( awsAssumedRoleArn, StringUtils.format("druid-kinesis-%s", UUID.randomUUID().toString())) .withStsClient(AWSSecurityTokenServiceClientBuilder.standard() .withCredentials(awsCredentialsProvider).build()); if (awsExternalId != null) { builder.withExternalId(awsExternalId); }//from ww w . j av a2 s . c om awsCredentialsProvider = builder.build(); } return AmazonKinesisClientBuilder.standard().withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, AwsHostNameUtils.parseRegion(endpoint, null))) .build(); }
From source file:org.ow2.proactive.scheduler.examples.S3ConnectorUtils.java
License:Open Source License
/** * Get or initialize the S3 client./*from ww w . j a v a 2 s. c om*/ * Note: this method must be synchronized because we're accessing the * field and we're calling this method from a worker thread. * * @return the S3 client */ protected static synchronized AmazonS3 getS3Client(String accessKey, String secretKey, String... args) { BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)); if (args.length == 1) { builder = builder.withRegion(args[0]); } else { String endpoint = args[0] + "://" + args[1]; String clientRegion = null; if (!ServiceUtils.isS3USStandardEndpoint(endpoint) && (clientRegion = AwsHostNameUtils .parseRegion(args[1], AmazonS3Client.S3_SERVICE_NAME)) == null) { throw new IllegalArgumentException("Invalid region in " + args[1]); } builder = builder .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, clientRegion)); } builder = builder.withPathStyleAccessEnabled(true); return builder.build(); }