Java Code Examples for com.amazonaws.regions.Region#getName()

The following examples show how to use com.amazonaws.regions.Region#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BucketLocationHandler.java    From teamcity-s3-artifact-storage-plugin with Apache License 2.0 5 votes vote down vote up
public static String getRegionName(@Nullable String location) {
  if (location == null) {
    return Regions.US_EAST_1.getName();
  }

  final Region region = RegionUtils.getRegion(location);
  if (region == null && location.equals("US")) {
    return Regions.US_EAST_1.getName();
  }
  if (region != null) {
    return !"US".equals(region.getName()) ? region.getName() : Regions.US_EAST_1.getName();
  } else {
    return location;
  }
}
 
Example 2
Source File: KmsMasterKeyProvider.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an instance of this object with the supplied configuration and credentials. all keys
 * listed in {@code keyIds} will be used to protect data.
 */
public KmsMasterKeyProvider(final AWSCredentialsProvider creds, final Region region,
        final ClientConfiguration clientConfiguration, final List<String> keyIds) {
    this(builder().withClientBuilder(AWSKMSClientBuilder.standard()
                                                        .withClientConfiguration(clientConfiguration)
                                                        .withCredentials(creds))
                  .clientFactory(),
         region.getName(),
         keyIds
    );
}
 
Example 3
Source File: DynamoDBConnectorUtilities.java    From dynamodb-cross-region-library with Apache License 2.0 5 votes vote down vote up
/**
 * Get the taskname from command line arguments if it exists, if not, autogenerate one to be used by KCL in the
 * checkpoint table and to publish CloudWatch metrics
 *
 * @param sourceRegion
 *            region of the source table
 * @param destinationRegion
 *            region of the destination table
 * @param suppliedTaskName
 *            the user supplied task name
 * @param sourceTableName
 *            the source table name
 * @param destinationTableName
 *            the destination table name
 * @return the generated task name
 */
public static String getTaskName(Region sourceRegion, Region destinationRegion, String suppliedTaskName,
                                 String sourceTableName, String destinationTableName) {
    String taskName;
    if (!Strings.isNullOrEmpty(suppliedTaskName)) {
        taskName = DynamoDBConnectorConstants.SERVICE_PREFIX + suppliedTaskName;
        if (taskName.length() > DynamoDBConnectorConstants.DYNAMODB_TABLENAME_LIMIT) {
            throw new IllegalArgumentException("Provided taskname is too long!");
        }
    } else {
        taskName = sourceRegion.getName() + sourceTableName + destinationRegion.getName() + destinationTableName;
        // hash stack name using MD5
        if (DynamoDBConnectorConstants.MD5_DIGEST == null) {
            // see if we can generate a taskname without hashing
            if (taskName.length() > DynamoDBConnectorConstants.DYNAMODB_TABLENAME_LIMIT) { // must hash the taskname
                throw new IllegalArgumentException(
                    "Generated taskname is too long and cannot be hashed due to improperly initialized MD5 digest object!");
            }
        } else {
            try {
                taskName = DynamoDBConnectorConstants.SERVICE_PREFIX
                        + new String(Hex.encodeHex(DynamoDBConnectorConstants.MD5_DIGEST.digest(taskName
                        .getBytes(DynamoDBConnectorConstants.BYTE_ENCODING))));
            } catch (UnsupportedEncodingException e) {
                throw new IllegalArgumentException("taskName was not encoded as " + DynamoDBConnectorConstants.BYTE_ENCODING, e);
            }
        }
    }

    return taskName;
}
 
Example 4
Source File: AmazonS3Provider.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Inject
public AmazonS3Provider(@S3CredentialsProvider AWSCredentialsProvider credentialsProvider, Region region) {
    this(credentialsProvider, region.getName());
}
 
Example 5
Source File: CommandLineInterface.java    From dynamodb-cross-region-library with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static AwsClientBuilder.EndpointConfiguration createEndpointConfiguration(Region region, Optional<String> endpoint, String endpointPrefix) {
    return new AwsClientBuilder.EndpointConfiguration(endpoint.or("https://" + region.getServiceEndpoint(endpointPrefix)), region.getName());
}
 
Example 6
Source File: AmazonResourceName.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public Builder withRegion(Region region) {
	this.region = region.getName();
	return this;
}
 
Example 7
Source File: KmsMasterKeyProvider.java    From aws-encryption-sdk-java with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an instance of this object with the supplied client and region; the client will be 
 * configured to use the provided region. All keys listed in {@code keyIds} will be used to 
 * protect data.
 *
 * @deprecated This constructor modifies the passed-in KMS client by setting its region. This functionality may be
 * removed in future releases. Use the builder to construct instances of this class instead.
 */
@Deprecated
public KmsMasterKeyProvider(final AWSKMS kms, final Region region, final List<String> keyIds) {
    this(requestedRegion -> kms, region.getName(), keyIds);

    kms.setRegion(region);
}