Example usage for com.amazonaws.regions RegionUtils getRegion

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

Introduction

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

Prototype

public static Region getRegion(String regionName) 

Source Link

Document

Returns the region with the given regionName and proper partition if found in region metadata.

Usage

From source file:com.kinesis.main.KinesisLogger.java

License:Apache License

public void start() {
    logger.info("Start Kinesis Logging!");

    String streamName = "SahilStockTradeStream";
    String regionName = "us-west-2";
    Region region = RegionUtils.getRegion(regionName);
    if (region == null) {
        System.err.println(regionName + " is not a valid AWS region.");
        System.exit(1);/*from  www . j  a  va2 s  . c  o  m*/
    }

    try {
        AWSCredentials credentials = CredentialUtils.getCredentialsProvider().getCredentials();
        AmazonKinesis kinesisClient = new AmazonKinesisClient(credentials,
                ConfigurationUtils.getClientConfigWithUserAgent());
        kinesisClient.setRegion(region);

        // Validate that the stream exists and is active
        validateStream(kinesisClient, streamName);

        // Repeatedly send stock trades with a 100 milliseconds wait in between
        while (true) {
            sendOauthJson(null, kinesisClient, streamName);
            Thread.sleep(getRandomNumberInRange(1, 5));
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.kinesisboard.amazonaws.utils.StreamSource.java

License:Open Source License

/**
 * Creates a new StreamSource.// w ww  .  j a va2  s . c  om
 * 
 * @param config
 *        Configuration to determine which stream to put records to and get {@link AWSCredentialsProvider}
 * @param inputFile
 *        File containing record data to emit on each line
 * @param loopOverStreamSource
 *        Loop over the stream source to continually put records
 */
public StreamSource(KinesisConnectorConfiguration config, String inputFile, boolean loopOverStreamSource) {
    this.config = config;
    this.inputFile = inputFile;
    this.loopOverInputFile = loopOverStreamSource;
    this.objectMapper = new ObjectMapper();
    kinesisClient = new AmazonKinesisClient(config.AWS_CREDENTIALS_PROVIDER);
    kinesisClient.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    if (config.KINESIS_ENDPOINT != null) {
        kinesisClient.setEndpoint(config.KINESIS_ENDPOINT);
    }
    KinesisUtils.createInputStream(config);
}

From source file:com.mweagle.tereus.commands.DeleteCommand.java

License:Open Source License

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "DM_EXIT", "OBL_UNSATISFIED_OBLIGATION" })
@Override/*  w  w w  .j  a va 2  s .com*/
public void run() {
    // Get the stack, delete the stack...
    int exitCode = 0;
    final Logger logger = LogManager.getLogger();

    try {
        final AmazonCloudFormationClient awsClient = new AmazonCloudFormationClient();
        awsClient.setRegion(RegionUtils.getRegion(this.region));
        final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(this.stackName);
        final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest);
        logger.info(describeResult);
        logger.info("Deleting stack: {}", this.stackName);

        if (this.dryRun) {
            logger.info("Dry run requested (-n/--noop). Stack deletion bypassed.");
        } else {
            final DeleteStackRequest deleteRequest = new DeleteStackRequest().withStackName(this.stackName);
            awsClient.deleteStack(deleteRequest);
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:com.threewks.thundr.deferred.provider.SqsQueueProvider.java

License:Apache License

public SqsQueueProvider(String deferredSqsAccessKey, String deferredSqsSecretKey, String deferredSqsRegion,
        String deferredSqsQueueName) {
    this(new BasicAWSCredentials(deferredSqsAccessKey, deferredSqsSecretKey),
            RegionUtils.getRegion(deferredSqsRegion), deferredSqsQueueName);
}

From source file:com.upplication.s3fs.AmazonS3Client.java

License:Open Source License

public void setRegion(String regionName) {
    Region region = RegionUtils.getRegion(regionName);
    if (region == null)
        throw new IllegalArgumentException("Not a valid S3 region name: " + regionName);
    client.setRegion(region);//from w w w  .  ja  va2 s.  c  o  m
}

From source file:com.zanox.vertx.mods.KinesisMessageProcessor.java

License:Apache License

private AmazonKinesisAsyncClient createClient() {

    // Building Kinesis configuration
    int connectionTimeout = getOptionalIntConfig(CONNECTION_TIMEOUT,
            ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT);
    int maxConnection = getOptionalIntConfig(MAX_CONNECTION, ClientConfiguration.DEFAULT_MAX_CONNECTIONS);

    // TODO: replace default retry policy
    RetryPolicy retryPolicy = ClientConfiguration.DEFAULT_RETRY_POLICY;
    int socketTimeout = getOptionalIntConfig(SOCKET_TIMEOUT, ClientConfiguration.DEFAULT_SOCKET_TIMEOUT);
    boolean useReaper = getOptionalBooleanConfig(USE_REAPER, ClientConfiguration.DEFAULT_USE_REAPER);
    String userAgent = getOptionalStringConfig(USER_AGENT, ClientConfiguration.DEFAULT_USER_AGENT);

    streamName = getMandatoryStringConfig(STREAM_NAME);
    partitionKey = getMandatoryStringConfig(PARTITION_KEY);
    region = getMandatoryStringConfig(REGION);

    logger.info(" --- Stream name: " + streamName);
    logger.info(" --- Partition key: " + partitionKey);
    logger.info(" --- Region: " + region);

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setConnectionTimeout(connectionTimeout);
    clientConfiguration.setMaxConnections(maxConnection);
    clientConfiguration.setRetryPolicy(retryPolicy);
    clientConfiguration.setSocketTimeout(socketTimeout);
    clientConfiguration.setUseReaper(useReaper);
    clientConfiguration.setUserAgent(userAgent);

    /*//from  w w  w.  ja  va 2  s.c om
    AWS credentials provider chain that looks for credentials in this order:
       Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
       Java System Properties - aws.accessKeyId and aws.secretKey
       Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI
       Instance profile credentials delivered through the Amazon EC2 metadata service
    */

    AWSCredentialsProvider awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();

    // Configuring Kinesis-client with configuration
    AmazonKinesisAsyncClient kinesisAsyncClient = new AmazonKinesisAsyncClient(awsCredentialsProvider,
            clientConfiguration);
    Region awsRegion = RegionUtils.getRegion(region);
    kinesisAsyncClient.setRegion(awsRegion);

    return kinesisAsyncClient;
}

From source file:io.fineo.drill.exec.store.dynamo.config.DynamoEndpoint.java

License:Apache License

@JsonIgnore
public void configure(AmazonDynamoDBAsyncClient client) {
    // set the region or the url, depending on the format
    if (regionOrUrl.contains(":")) {
        client.setEndpoint(regionOrUrl);
    } else {/* w w w .j a  v  a2s .co m*/
        client.setRegion(RegionUtils.getRegion(regionOrUrl));
    }
}

From source file:jp.buyee.glover.KinesisConnectorExecutor.java

License:Open Source License

/**
 * Helper method to create Elasticsearch cluster at set correct endpoint.
 *///  w w  w .  j a  va 2  s.  c om
private void createElasticsearchCluster() {
    // Create stack if not already up
    AmazonCloudFormation cloudFormationClient = new AmazonCloudFormationClient(config.AWS_CREDENTIALS_PROVIDER);
    cloudFormationClient.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    CloudFormationUtils.createStackIfNotExists(cloudFormationClient, config);

    // Update the elasticsearch endpoint to use endpoint in created cluster
    AmazonEC2 ec2Client = new AmazonEC2Client(config.AWS_CREDENTIALS_PROVIDER);
    ec2Client.setRegion(RegionUtils.getRegion(config.REGION_NAME));
    config.ELASTICSEARCH_ENDPOINT = EC2Utils.getEndpointForFirstActiveInstanceWithTag(ec2Client,
            EC2_ELASTICSEARCH_FILTER_NAME, EC2_ELASTICSEARCH_FILTER_VALUE);
    if (config.ELASTICSEARCH_ENDPOINT == null || config.ELASTICSEARCH_ENDPOINT.isEmpty()) {
        throw new RuntimeException("Could not find active Elasticsearch endpoint from cluster.");
    }
}

From source file:jp.classmethod.aws.gradle.AwsPluginExtension.java

License:Apache License

public Region getActiveRegion(String clientRegion) {
    if (clientRegion != null) {
        return RegionUtils.getRegion(clientRegion);
    }/*from   www . j  a v  a  2 s .c o  m*/
    if (this.region == null) {
        throw new IllegalStateException("default region is null");
    }
    return RegionUtils.getRegion(region);
}

From source file:net.firejack.aws.web.controller.AWSController.java

License:Apache License

@ResponseBody
@ExceptionHandler(Exception.class)
@RequestMapping(value = "region/{region}", method = RequestMethod.GET)
public InstanceDetails changeRegion(@PathVariable("region") String region) {
    if (amazonEC2 == null)
        throw new AmazonServiceException("Amazon service can't initialize");
    if (region.isEmpty())
        throw new AmazonServiceException("Region is empty");

    amazonEC2.setRegion(RegionUtils.getRegion(region));

    InstanceDetails details = new InstanceDetails();

    DescribeImagesRequest request = new DescribeImagesRequest();
    request.setOwners(Arrays.asList(owner));
    DescribeImagesResult result = amazonEC2.describeImages(request);

    List<Image> images = result.getImages();
    List<Dropdown> amis = new ArrayList<Dropdown>(images.size());

    for (Image image : images)
        amis.add(new Dropdown(image.getImageId(), image.getName()));
    details.setAmis(amis);/*from   w w w .j a  v a 2 s .c o m*/

    DescribeSecurityGroupsResult securityGroupsResult = amazonEC2.describeSecurityGroups();

    List<SecurityGroup> securityGroups = securityGroupsResult.getSecurityGroups();
    List<Dropdown> groups = new ArrayList<Dropdown>(securityGroups.size());

    for (SecurityGroup group : securityGroups)
        groups.add(new Dropdown(group.getGroupId(), group.getGroupName()));
    details.setSecurityGroups(groups);

    DescribeKeyPairsResult keyPairsResult = amazonEC2.describeKeyPairs();

    List<KeyPairInfo> keyPairInfos = keyPairsResult.getKeyPairs();
    List<Dropdown> keyPairs = new ArrayList<Dropdown>(keyPairInfos.size());

    for (KeyPairInfo keyPairInfo : keyPairInfos)
        keyPairs.add(new Dropdown(keyPairInfo.getKeyName(), keyPairInfo.getKeyName()));
    details.setKeys(keyPairs);
    details.setInstanceTypes(InstanceType.values());

    return details;
}