Example usage for com.amazonaws.services.kms AWSKMSClient getServiceName

List of usage examples for com.amazonaws.services.kms AWSKMSClient getServiceName

Introduction

In this page you can find the example usage for com.amazonaws.services.kms AWSKMSClient getServiceName.

Prototype

public String getServiceName() 

Source Link

Document

Returns the service abbreviation for this service, used for identifying service endpoints by region, identifying the necessary signer, etc.

Usage

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Returns the KMS endpoint URL for the specified region.
 *
 * @param kmsClient  the KMS client/*from  w  ww.j  a  va  2  s  .com*/
 * @param regionName the desired region
 * @return the endpoint URL for the specified region
 * @throws IllegalArgumentException if the endpoint cannot be determined
 */
private static String getKMSEndpointForRegion(AWSKMSClient kmsClient, String regionName) {
    checkNotNull(kmsClient, "kmsClient is null");
    checkNotNull(regionName, "regionName is null");

    com.amazonaws.regions.Region region = RegionUtils.getRegion(regionName);

    if (region == null) {
        throw new IllegalArgumentException(String.format("Unable to find the region %s", regionName));
    }

    String serviceName = kmsClient.getServiceName();
    String protocolPrefix = region.hasHttpsEndpoint(serviceName) ? "https://" : "http://";
    return protocolPrefix + region.getServiceEndpoint(serviceName);
}