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:util.SQSManager.java

License:Open Source License

private void createQueue(String name) throws Exception {
    /*// w ww . j ava 2 s. c  o m
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * ().
     */
    AWSCredentials credentials = null;
    try {
        PropertiesManager properitesManager = PropertiesManager.getInstance();
        credentials = new BasicAWSCredentials(properitesManager.getAccessKey(),
                properitesManager.getSecretKey());
        sqs = new AmazonSQSClient(credentials);
        Region apSouthEast = Region.getRegion(Regions.fromName(properitesManager.getRegion()));//Region in Singapore
        sqs.setRegion(apSouthEast);
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/daniel/.aws/credentials), and is in valid format.", e);
    }

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SQS");
    System.out.println("===========================================\n");

    try {
        // Create a queue
        System.out.println("Creating a new SQS queue called " + name + ".\n");
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(name);
        myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();

        // List queues
        System.out.println("Listing all queues in your account.\n");
        for (String queueUrl : sqs.listQueues().getQueueUrls()) {
            System.out.println("  QueueUrl: " + queueUrl);
        }
        System.out.println("Create queue successfully");
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SQS, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
        throw ase;
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with SQS, such as not "
                + "being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
        throw ace;
    }
}

From source file:ws.salient.aws.AmazonClientProvider.java

License:Apache License

public AmazonClientProvider() {
    Region region = Regions.getCurrentRegion();
    if (region == null) {
        region = Region.getRegion(Regions.US_EAST_1);
    }/*from  ww  w .ja  v a  2  s . c o m*/
    s3 = new AmazonS3Client().withRegion(region);
    kms = new AWSKMSClient().withRegion(region);
    dynamodb = new DynamoDB(new AmazonDynamoDBClient().withRegion(region));
    lambda = new AWSLambdaClient().withRegion(region);
}

From source file:zipkin.sparkstreaming.stream.kinesis.KinesisStreamFactory.java

License:Apache License

KinesisStreamFactory(Builder builder) {
    this.stream = builder.stream;
    this.app = builder.app;
    this.regionName = builder.awsRegion;
    this.endpoint = builder.awsEndpoint != null ? builder.awsEndpoint
            : Region.getRegion(Regions.fromName(regionName)).getServiceEndpoint(AmazonKinesis.ENDPOINT_PREFIX);

    this.checkpointInterval = builder.checkpointInterval;
    this.initialPositionInStream = builder.initialPositionInStream;
    this.storageLevel = builder.storageLevel;

    this.awsAccessKeyId = builder.awsAccessKeyId;
    this.awsSecretKey = builder.awsSecretKey;
}