Example usage for com.amazonaws.regions AwsRegionProvider AwsRegionProvider

List of usage examples for com.amazonaws.regions AwsRegionProvider AwsRegionProvider

Introduction

In this page you can find the example usage for com.amazonaws.regions AwsRegionProvider AwsRegionProvider.

Prototype

AwsRegionProvider

Source Link

Usage

From source file:com.netflix.genie.common.internal.configs.AwsAutoConfiguration.java

License:Apache License

/**
 * Get an AWS region provider instance. The rules for this basically follow what Spring Cloud AWS does but uses
 * the interface from the AWS SDK instead and provides a sensible default.
 * <p>/*w ww  . j  av  a 2s .  c  om*/
 * See: <a href="https://tinyurl.com/y9edl6yr">Spring Cloud AWS Region Documentation</a>
 *
 * @param awsRegionProperties The cloud.aws.region.* properties
 * @return A region provider based on whether static was set by user, else auto, else default of us-east-1
 */
@Bean
@ConditionalOnMissingBean(AwsRegionProvider.class)
public AwsRegionProvider awsRegionProvider(final AwsRegionProperties awsRegionProperties) {
    final String staticRegion = awsRegionProperties.getStatic();
    if (StringUtils.isNotBlank(staticRegion)) {
        // Make sure we have a valid region. Will throw runtime exception if not.
        final Regions region = Regions.fromName(staticRegion);
        return new AwsRegionProvider() {
            /**
             * Always return the static configured region.
             *
             * {@inheritDoc}
             */
            @Override
            public String getRegion() throws SdkClientException {
                return region.getName();
            }
        };
    } else if (awsRegionProperties.isAuto()) {
        return new DefaultAwsRegionProviderChain();
    } else {
        // Sensible default
        return new AwsRegionProvider() {
            /**
             * Always default to us-east-1.
             *
             * {@inheritDoc}
             */
            @Override
            public String getRegion() throws SdkClientException {
                return Regions.US_EAST_1.getName();
            }
        };
    }
}