Example usage for com.amazonaws.regions Region getRegion

List of usage examples for com.amazonaws.regions Region getRegion

Introduction

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

Prototype

public static Region getRegion(Regions region) 

Source Link

Document

Returns the region with the id given, or null if it cannot be found in the current regions.xml file.

Usage

From source file:io.fineo.client.auth.CognitoCredentialsProvider.java

License:Open Source License

/**
 * Constructs a new {@link CognitoCredentialsProvider}, which will use the
 * specified Amazon Cognito identity pool to make a request, using the basic
 * authentication flow, to the AWS Security Token Service (STS) to request
 * short-lived session credentials, which will then be returned by this
 * class's {@link #getCredentials()} method.
 * <p>//from  www . j av  a  2 s.com
 * This version of the constructor allows you to specify a client
 * configuration for the Amazon Cognito and STS clients.
 * </p>
 *
 * @param accountId The AWS accountId for the account with Amazon Cognito
 * @param identityPoolId The Amazon Cognito identity pool to use
 * @param unauthRoleArn The ARN of the IAM Role that will be assumed when
 *            unauthenticated
 * @param authRoleArn The ARN of the IAM Role that will be assumed when
 *            authenticated
 * @param region The region to use when contacting Cognito Identity
 * @param clientConfiguration Configuration to apply to service clients
 *            created
 */
public CognitoCredentialsProvider(String accountId, String identityPoolId, String unauthRoleArn,
        String authRoleArn, Regions region, ClientConfiguration clientConfiguration) {
    this(accountId, identityPoolId, unauthRoleArn, authRoleArn,
            new AmazonCognitoIdentityClient(new AnonymousAWSCredentials(), clientConfiguration),
            (unauthRoleArn == null && authRoleArn == null) ? null
                    : new AWSSecurityTokenServiceClient(new AnonymousAWSCredentials(), clientConfiguration));
    this.cib.setRegion(Region.getRegion(region));
}

From source file:io.fineo.client.auth.CognitoCredentialsProvider.java

License:Open Source License

/**
 * Constructs a new CognitoCredentialsProvider, which will set up a link to
 * the provider passed in using the enhanced authentication flow to get
 * short-lived credentials from Amazon Cognito, which can be retrieved from
 * {@link #getCredentials()}/*  w w w  .  ja  v  a 2  s. c  o m*/
 * <p>
 * This version of the constructor allows you to specify your own Identity
 * Provider class and the configuration for the Amazon Cognito client.
 * </p>
 *
 * @param provider a reference to the provider in question, including what's
 *            needed to interact with it to later connect with Amazon
 *            Cognito
 * @param clientConfiguration Configuration to apply to service clients
 *            created
 * @param region The region to use when contacting Cognito Identity
 */
public CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, Regions region,
        ClientConfiguration clientConfiguration) {
    this(provider, new AmazonCognitoIdentityClient(new AnonymousAWSCredentials(), clientConfiguration));
    this.cib.setRegion(Region.getRegion(region));
}

From source file:io.ignitr.dispatchr.manager.Application.java

License:Apache License

@Autowired
@Bean//www.jav  a 2s  .c  om
public AmazonSNSClient amazonSNSClient(DeploymentContext deploymentContext) {
    AmazonSNSClient client = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain());
    client.setRegion(Region.getRegion(Regions.fromName(deploymentContext.getRegion())));

    return client;
}

From source file:io.ignitr.dispatchr.manager.Application.java

License:Apache License

@Autowired
@Bean/*w w w  . j  a v a 2  s .  c  o  m*/
public AmazonDynamoDBClient amazonDynamoDBClient(DeploymentContext deploymentContext) {
    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain());
    client.setRegion(Region.getRegion(Regions.fromName(deploymentContext.getRegion())));

    return client;
}

From source file:io.kodokojo.config.module.AwsModule.java

License:Open Source License

@Provides
@Singleton//from  w  w w .  j a v  a 2  s .c  om
DnsManager provideDnsManager(ApplicationConfig applicationConfig, AwsConfig awsConfig) {
    AWSCredentials credentials = null;
    try {
        DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();
        credentials = defaultAWSCredentialsProviderChain.getCredentials();
    } catch (RuntimeException e) {
        LOGGER.warn("Unable to retrieve AWS credentials.");
    }
    if (StringUtils.isNotBlank(System.getenv("NO_DNS")) || credentials == null) {
        LOGGER.info("Using NoOpDnsManager as DnsManger implementation");
        return new NoOpDnsManager();
    } else {
        LOGGER.info("Using Route53DnsManager as DnsManger implementation");
        return new Route53DnsManager(applicationConfig.domain(),
                Region.getRegion(Regions.fromName(awsConfig.region())));
    }
}

From source file:io.kodokojo.config.module.AwsModule.java

License:Open Source License

@Provides
@Singleton//from   www  .  j a va  2s.co m
EmailSender provideEmailSender(AwsConfig awsConfig, EmailConfig emailConfig) {
    if (StringUtils.isBlank(emailConfig.smtpHost())) {
        AWSCredentials credentials = null;
        try {
            DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain();
            credentials = defaultAWSCredentialsProviderChain.getCredentials();
        } catch (RuntimeException e) {
            LOGGER.warn("Unable to retrieve AWS credentials.");
        }
        if (credentials == null) {
            return new NoopEmailSender();
        } else {
            return new SesEmailSender(emailConfig.smtpFrom(),
                    Region.getRegion(Regions.fromName(awsConfig.region())));
        }
    } else {
        return new SmtpEmailSender(emailConfig.smtpHost(), emailConfig.smtpPort(), emailConfig.smtpUsername(),
                emailConfig.smtpPassword(), emailConfig.smtpFrom());
    }
}

From source file:io.kodokojo.service.aws.Route53DnsManager.java

License:Open Source License

public Route53DnsManager(String domainName, Region region) {
    if (isBlank(domainName)) {
        throw new IllegalArgumentException("domainName must be defined.");
    }//from  w w  w. j  a va  2s. c  o m
    this.domainName = domainName.endsWith(".") ? domainName : domainName + ".";

    AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials();
    client = new AmazonRoute53Client(credentials);
    client.setRegion(region == null ? Region.getRegion(Regions.EU_WEST_1) : region);
}

From source file:io.konig.camel.aws.s3.DeleteObjectEndpoint.java

License:Apache License

@Override
public void doStart() throws Exception {
    super.doStart();
    String envName = "";
    if (System.getProperty("environmentName") != null) {
        envName = System.getProperty("environmentName");
    }/*from  w ww  .  ja v a2 s  . co m*/
    String bucketName = getConfiguration().getBucketName();
    bucketName = bucketName.replace("${environmentName}", envName);
    configuration.setBucketName(bucketName);
    configuration.getAmazonS3Client().setRegion(Region.getRegion(Regions.fromName(configuration.getRegion())));
    s3Client = configuration.getAmazonS3Client() != null ? configuration.getAmazonS3Client()
            : S3ClientFactory.getAWSS3Client(configuration, getMaxConnections()).getS3Client();

    String fileName = getConfiguration().getFileName();

    if (fileName != null) {
        LOG.trace("File name [{}] requested, so skipping bucket check...", fileName);
        return;
    }

    LOG.trace("Querying whether bucket [{}] already exists...", bucketName);

    String prefix = getConfiguration().getPrefix();

    try {
        s3Client.listObjects(new ListObjectsRequest(bucketName, prefix, null, null, 0));
        LOG.trace("Bucket [{}] already exists", bucketName);
        return;
    } catch (AmazonServiceException ase) {
        /* 404 means the bucket doesn't exist */
        if (ase.getStatusCode() != 404) {
            throw ase;
        }
    }

    LOG.trace("Bucket [{}] doesn't exist yet", bucketName);

    // creates the new bucket because it doesn't exist yet
    CreateBucketRequest createBucketRequest = new CreateBucketRequest(getConfiguration().getBucketName());

    //LOG.trace("Creating bucket [{}] in region [{}] with request [{}]...", configuration.getBucketName(), configuration.getRegion(), createBucketRequest);

    s3Client.createBucket(createBucketRequest);

    LOG.trace("Bucket created");

    if (configuration.getPolicy() != null) {
        LOG.trace("Updating bucket [{}] with policy [{}]", bucketName, configuration.getPolicy());

        s3Client.setBucketPolicy(bucketName, configuration.getPolicy());

        LOG.trace("Bucket policy updated");
    }
}

From source file:io.macgyver.plugin.cloud.aws.AWSServiceClientImpl.java

License:Apache License

@Override
public AmazonEC2Client createEC2Client(Regions region) {
    return createEC2Client(Region.getRegion(region));
}

From source file:io.macgyver.plugin.cloud.aws.AWSServiceClientImpl.java

License:Apache License

void assignRegion(AmazonWebServiceClient c, Regions r) {
    c.setRegion(Region.getRegion(r));
}