Example usage for com.amazonaws.regions Region getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

The unique system ID for this region; ex: "us-east-1".

Usage

From source file:awslabs.lab21.SolutionCode.java

License:Open Source License

@Override
public void createBucket(AmazonS3 s3Client, String bucketName, Region region) {
    // Construct a CreateBucketRequest object that contains the provided bucket name.
    // If the region is other than us-east-1, we need to specify a regional constraint.
    CreateBucketRequest createBucketRequest;
    if (region.getName().equals("us-east-1")) {
        createBucketRequest = new CreateBucketRequest(bucketName);
    } else {/*from  ww w  .  ja v a  2s  .  c  o  m*/
        createBucketRequest = new CreateBucketRequest(bucketName,
                com.amazonaws.services.s3.model.Region.fromValue(region.getName()));
    }

    // Submit the request using the createBucket method of the s3Client object.
    s3Client.createBucket(createBucketRequest);

}

From source file:awslabs.lab41.SolutionCode.java

License:Open Source License

@Override
public void prepMode_CreateBucket(AmazonS3Client s3Client, String bucketName, Region region) {
    // Construct a CreateBucketRequest object that contains the provided bucket name.
    // If the region is other than us-east-1, we need to specify a regional constraint.
    CreateBucketRequest createBucketRequest;
    if (region.getName().equals("us-east-1")) {
        createBucketRequest = new CreateBucketRequest(bucketName);
    } else {//w  w w  . j av  a2  s .  c o m
        createBucketRequest = new CreateBucketRequest(bucketName,
                com.amazonaws.services.s3.model.Region.fromValue(region.getName()));
    }
    s3Client.createBucket(createBucketRequest);
}

From source file:br.com.ingenieux.mojo.beanstalk.util.EnvironmentHostnameUtil.java

License:Apache License

public static Predicate<EnvironmentDescription> getHostnamePredicate(Region region, String cnamePrefix) {
    final Set<String> hostnamesToMatch = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);

    hostnamesToMatch.add(format("%s.elasticbeanstalk.com", cnamePrefix).toLowerCase());
    hostnamesToMatch.add(format("%s.%s.elasticbeanstalk.com", cnamePrefix, region.getName()).toLowerCase());

    return new Predicate<EnvironmentDescription>() {
        @Override/*from  w  w  w  . j av a 2s . co m*/
        public boolean apply(EnvironmentDescription t) {
            return hostnamesToMatch.contains(t.getCNAME());
        }

        @Override
        public String toString() {
            return format("... with cname belonging to %s",
                    StringUtils.join(hostnamesToMatch.iterator(), " or "));
        }
    };
}

From source file:com.alertlogic.aws.kinesis.test1.StreamProcessor.java

License:Open Source License

/**
 * Start the Kinesis Client application.
 * /*from   ww w  .j a va  2 s  . co m*/
 * @param args Expecting 4 arguments: Application name to use for the Kinesis Client Application, Stream name to
 *        read from, DynamoDB table name to persist counts into, and the AWS region in which these resources
 *        exist or should be created.
 */
public static void main(String[] args) throws UnknownHostException {
    if (args.length != 4) {
        System.err.println("Usage: " + StreamProcessor.class.getSimpleName()
                + " <application name> <stream name> <DynamoDB table name> <region>");
        System.exit(1);
    }

    String applicationName = args[0];
    String streamName = args[1];
    String countsTableName = args[2];
    Region region = SampleUtils.parseRegion(args[3]);

    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
    ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration());
    AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig);
    kinesis.setRegion(region);
    AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig);
    dynamoDB.setRegion(region);

    // Creates a stream to write to, if it doesn't exist
    StreamUtils streamUtils = new StreamUtils(kinesis);
    streamUtils.createStreamIfNotExists(streamName, 2);
    LOG.info(String.format("%s stream is ready for use", streamName));

    DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB);
    dynamoDBUtils.createCountTableIfNotExists(countsTableName);
    LOG.info(String.format("%s DynamoDB table is ready for use", countsTableName));

    String workerId = String.valueOf(UUID.randomUUID());
    LOG.info(String.format("Using working id: %s", workerId));
    KinesisClientLibConfiguration kclConfig = new KinesisClientLibConfiguration(applicationName, streamName,
            credentialsProvider, workerId);
    kclConfig.withCommonClientConfig(clientConfig);
    kclConfig.withRegionName(region.getName());
    kclConfig.withInitialPositionInStream(InitialPositionInStream.LATEST);

    // Persist counts to DynamoDB
    DynamoDBCountPersister persister = new DynamoDBCountPersister(
            dynamoDBUtils.createMapperForTable(countsTableName));

    IRecordProcessorFactory recordProcessor = new CountingRecordProcessorFactory<HttpReferrerPair>(
            HttpReferrerPair.class, persister, COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS, COMPUTE_INTERVAL_IN_MILLIS);

    Worker worker = new Worker(recordProcessor, kclConfig);

    int exitCode = 0;
    try {
        worker.run();
    } catch (Throwable t) {
        LOG.error("Caught throwable while processing data.", t);
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:com.bodybuilding.turbine.discovery.AsgTagInstanceDiscovery.java

License:Apache License

protected AsgTagInstanceDiscovery(AmazonAutoScalingClient asgClient, AmazonEC2Client ec2Client) {
    Preconditions.checkNotNull(asgClient);
    Preconditions.checkNotNull(ec2Client);
    Preconditions.checkState(!Strings.isNullOrEmpty(CLUSTER_TAG_KEY.get()),
            TAG_PROPERTY_NAME + " must be supplied!");
    this.asgClient = asgClient;
    this.ec2Client = ec2Client;

    String regionName = DynamicPropertyFactory.getInstance().getStringProperty("turbine.region", "").get();
    if (Strings.isNullOrEmpty(regionName)) {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            regionName = currentRegion.getName();
        } else {/*from w  ww. j a v  a 2  s .c om*/
            regionName = "us-east-1";
        }
    }
    Region region = Region.getRegion(Regions.fromName(regionName));
    ec2Client.setRegion(region);
    asgClient.setRegion(region);
    log.debug("Set the region to [{}]", region);
}

From source file:com.bodybuilding.turbine.discovery.Ec2TagInstanceDiscovery.java

License:Apache License

protected Ec2TagInstanceDiscovery(AmazonEC2Client ec2Client) {
    Preconditions.checkNotNull(ec2Client);
    this.ec2Client = ec2Client;

    Preconditions.checkState(!Strings.isNullOrEmpty(CLUSTER_TAG_KEY.get()),
            PROPERTY_NAME + " must be supplied!");
    String regionName = DynamicPropertyFactory.getInstance().getStringProperty("turbine.region", "").get();
    if (Strings.isNullOrEmpty(regionName)) {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            regionName = currentRegion.getName();
        } else {//w w  w  . ja  va 2  s . c  om
            regionName = "us-east-1";
        }
    }
    ec2Client.setRegion(Region.getRegion(Regions.fromName(regionName)));
    log.debug("Set the ec2 region to [{}]", regionName);
}

From source file:com.calamp.services.kinesis.events.processor.CalAmpEventProcessor.java

License:Open Source License

public static void main(String[] args) throws Exception {
    checkUsage(args);/*from   ww  w .ja  va2s . c  o m*/
    //String applicationName = args[0];
    //String streamName = args[1];
    //Region region = RegionUtils.getRegion(args[2]);
    boolean isUnordered = Boolean.valueOf(args[3]);
    String applicationName = isUnordered ? CalAmpParameters.sortAppName : CalAmpParameters.consumeAppName;
    String streamName = isUnordered ? CalAmpParameters.unorderdStreamName : CalAmpParameters.orderedStreamName;
    Region region = RegionUtils.getRegion(CalAmpParameters.regionName);

    if (region == null) {
        System.err.println(args[2] + " is not a valid AWS region.");
        System.exit(1);
    }

    setLogLevels();
    AWSCredentialsProvider credentialsProvider = CredentialUtils.getCredentialsProvider();
    ClientConfiguration cc = ConfigurationUtils.getClientConfigWithUserAgent(true);
    AmazonKinesis kinesisClient = new AmazonKinesisClient(credentialsProvider, cc);
    kinesisClient.setRegion(region);

    //Utils.kinesisClient = kinesisClient;

    String workerId = String.valueOf(UUID.randomUUID());
    KinesisClientLibConfiguration kclConfig = new KinesisClientLibConfiguration(applicationName, streamName,
            credentialsProvider, workerId).withRegionName(region.getName()).withCommonClientConfig(cc)
                    .withMaxRecords(com.calamp.services.kinesis.events.utils.CalAmpParameters.maxRecPerPoll)
                    .withIdleTimeBetweenReadsInMillis(
                            com.calamp.services.kinesis.events.utils.CalAmpParameters.pollDelayMillis)
                    .withCallProcessRecordsEvenForEmptyRecordList(CalAmpParameters.alwaysPoll)
                    .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);

    IRecordProcessorFactory processorFactory = new RecordProcessorFactory(isUnordered);

    // Create the KCL worker with the stock trade record processor factory
    Worker worker = new Worker(processorFactory, kclConfig);

    int exitCode = 0;
    try {
        worker.run();
    } catch (Throwable t) {
        LOG.error("Caught throwable while processing data.", t);
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:com.facebook.presto.hive.metastore.glue.GlueHiveMetastore.java

License:Apache License

private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config) {
    ClientConfiguration clientConfig = new ClientConfiguration()
            .withMaxConnections(config.getMaxGlueConnections());
    AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard()
            .withClientConfiguration(clientConfig);

    if (config.getGlueRegion().isPresent()) {
        asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
    } else if (config.getPinGlueClientToCurrentRegion()) {
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            asyncGlueClientBuilder.setRegion(currentRegion.getName());
        }//  w  w  w.j  a  v a 2 s .com
    }

    return asyncGlueClientBuilder.build();
}

From source file:com.facebook.presto.hive.s3.PrestoS3ClientFactory.java

License:Apache License

synchronized AmazonS3 getS3Client(Configuration config, HiveClientConfig clientConfig) {
    if (s3Client != null) {
        return s3Client;
    }/* w ww.  ja va2s. c o m*/

    HiveS3Config defaults = new HiveS3Config();
    String userAgentPrefix = config.get(S3_USER_AGENT_PREFIX, defaults.getS3UserAgentPrefix());
    int maxErrorRetries = config.getInt(S3_MAX_ERROR_RETRIES, defaults.getS3MaxErrorRetries());
    boolean sslEnabled = config.getBoolean(S3_SSL_ENABLED, defaults.isS3SslEnabled());
    Duration connectTimeout = Duration
            .valueOf(config.get(S3_CONNECT_TIMEOUT, defaults.getS3ConnectTimeout().toString()));
    Duration socketTimeout = Duration
            .valueOf(config.get(S3_SOCKET_TIMEOUT, defaults.getS3SocketTimeout().toString()));
    int maxConnections = config.getInt(S3_SELECT_PUSHDOWN_MAX_CONNECTIONS,
            clientConfig.getS3SelectPushdownMaxConnections());

    if (clientConfig.isS3SelectPushdownEnabled()) {
        s3UserAgentSuffix = "presto-select";
    }

    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(maxErrorRetries)
            .withProtocol(sslEnabled ? Protocol.HTTPS : Protocol.HTTP)
            .withConnectionTimeout(toIntExact(connectTimeout.toMillis()))
            .withSocketTimeout(toIntExact(socketTimeout.toMillis())).withMaxConnections(maxConnections)
            .withUserAgentPrefix(userAgentPrefix).withUserAgentSuffix(s3UserAgentSuffix);

    PrestoS3FileSystemStats stats = new PrestoS3FileSystemStats();
    RequestMetricCollector metricCollector = new PrestoS3FileSystemMetricCollector(stats);
    AWSCredentialsProvider awsCredentialsProvider = getAwsCredentialsProvider(config, defaults);
    AmazonS3Builder<? extends AmazonS3Builder, ? extends AmazonS3> clientBuilder = AmazonS3Client.builder()
            .withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration)
            .withMetricsCollector(metricCollector).enablePathStyleAccess();

    boolean regionOrEndpointSet = false;

    String endpoint = config.get(S3_ENDPOINT);
    boolean pinS3ClientToCurrentRegion = config.getBoolean(S3_PIN_CLIENT_TO_CURRENT_REGION,
            defaults.isPinS3ClientToCurrentRegion());
    verify(!pinS3ClientToCurrentRegion || endpoint == null,
            "Invalid configuration: either endpoint can be set or S3 client can be pinned to the current region");

    // use local region when running inside of EC2
    if (pinS3ClientToCurrentRegion) {
        Region region = Regions.getCurrentRegion();
        if (region != null) {
            clientBuilder.withRegion(region.getName());
            regionOrEndpointSet = true;
        }
    }

    if (!isNullOrEmpty(endpoint)) {
        clientBuilder.withEndpointConfiguration(new EndpointConfiguration(endpoint, null));
        regionOrEndpointSet = true;
    }

    if (!regionOrEndpointSet) {
        clientBuilder.withRegion(US_EAST_1);
        clientBuilder.setForceGlobalBucketAccessEnabled(true);
    }

    s3Client = clientBuilder.build();
    return s3Client;
}

From source file:com.hangum.tadpole.aws.rds.commons.core.utils.AmazonRDSUtsils.java

License:Open Source License

/**
 * list region name/*from   w  ww  .  j  a v a2 s. c  om*/
 * 
 * @return
 */
public static List<String> getRDSRegionList() {
    List<String> listRegion = new ArrayList<String>();

    for (Region region : RegionUtils.getRegionsForService(ServiceAbbreviations.RDS)) {
        listRegion.add(region.getName());
    }

    return listRegion;
}