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:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.KinesisStreamDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;// w  w  w .j  av  a 2  s.c o  m

    try {

        AmazonKinesis client = new AmazonKinesisClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeStreamRequest request = new DescribeStreamRequest();
        request.setStreamName(detailRequest.getResourceName());

        DescribeStreamResult result = client.describeStream(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving Kinesis details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.RdsInstanceDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*  w  w w  .ja v  a2  s. c o m*/

    try {

        AmazonRDS client = new AmazonRDSClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeDBInstancesRequest request = new DescribeDBInstancesRequest();
        request.setDBInstanceIdentifier(detailRequest.getResourceName());

        DescribeDBInstancesResult result = client.describeDBInstances(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving RDS details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.SnsTopic.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//  w  w w  . ja  v a 2  s  . c  om

    try {

        AmazonSNS client = new AmazonSNSClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        buildUI(null);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving SNS details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.SqsQueueDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*from   ww  w.jav a 2s .co  m*/

    try {

        AmazonSQS client = new AmazonSQSClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        buildUI(null);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving SQS details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.SwfDomainDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*from w  w w .j  a  va  2 s .co m*/

    try {

        AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeDomainRequest request = new DescribeDomainRequest();
        request.setName(detailRequest.getResourceName());

        DomainDetail result = client.describeDomain(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving SWF details from AWS", e);
    }

    return response;
}

From source file:com.hiveTown.util.AmazonSESUtil.java

License:Open Source License

private AmazonSimpleEmailServiceClient getClient() {

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials.
    AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
    Region REGION = Region.getRegion(Regions.US_WEST_2);
    client.setRegion(REGION);/*from  w ww. ja  va  2  s .c om*/
    return client;
}

From source file:com.hussi.aws.dynamoDB.AmazonDynamoDBSample.java

License:Open Source License

/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.ProfilesConfigFile
 * @see com.amazonaws.ClientConfiguration
 */// w  w w  .j  a  v a 2  s  . c  o m
private static void init() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (~/.aws/credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
        System.out.println("credentials.getAWSAccessKeyId()===>>>" + credentials.getAWSAccessKeyId());
        System.out.println("credentials.getAWSSecretKey()===>>>" + credentials.getAWSSecretKey());
        //System.exi   t(0);

    } 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 (~/.aws/credentials), and is in valid format.", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
}

From source file:com.ibm.connectors.AmazonSQS.AmazonSQSInputConnector.java

License:Open Source License

@Override
public void poll(long waitInterval) {
    Properties properties = new Properties();

    String access_key_id = getProperty("AccessKeyId");
    String secret_access_key = getProperty("SecretAccessKey");
    BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);

    AmazonSQS sqs = new AmazonSQSClient(credentials);

    // Region selection
    Region region = Region.getRegion(Regions.fromName(getProperty("region")));
    sqs.setRegion(region);//from  w  w  w .j a  v a 2s  .  com

    GetQueueUrlResult queueUrl = sqs.getQueueUrl(getProperty("Queue"));

    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl.getQueueUrl());
    List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

    String outputMessage = "";
    // if there are messages then do the processing
    if (messages.size() > 0) {

        //append the message properties to the localenv tree
        for (Message message : messages) {
            properties.setProperty("MessageId", message.getMessageId());
            properties.setProperty("ReceiptHandle", message.getReceiptHandle());
            properties.setProperty("MD5OfBody", message.getMD5OfBody());
            // get the message body to a string
            outputMessage = message.getBody();
        }
        properties.setProperty("queueUrl", queueUrl.getQueueUrl());
        // delete the message from the queue
        String messageReceiptHandle = messages.get(0).getReceiptHandle();
        sqs.deleteMessage(new DeleteMessageRequest(queueUrl.getQueueUrl(), messageReceiptHandle));
        ConnectorCallback callback = getCallback();
        callback.processInboundData(outputMessage.getBytes(), properties);
    }
}

From source file:com.ibm.connectors.AmazonSQS.AmazonSQSOutputInteraction.java

License:Open Source License

@Override
public Properties send(Properties properties, Object message) throws ConnectorException {

    String access_key_id = properties.getProperty("AccessKeyId");
    String secret_access_key = properties.getProperty("SecretAccessKey");
    BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);

    AmazonSQS sqs = new AmazonSQSClient(credentials);
    //System.out.println(properties.getProperty("region"));
    // Region selection
    Region region = Region.getRegion(Regions.fromName(properties.getProperty("region")));
    sqs.setRegion(region);// w w w  .j  a v  a 2s  .c  o m

    GetQueueUrlResult queueUrl = sqs.getQueueUrl(properties.getProperty("Queue"));
    String messageStr = new String((byte[]) message);

    sqs.sendMessage(new SendMessageRequest(queueUrl.getQueueUrl(), messageStr));

    return properties;
}

From source file:com.imos.sample.S3SampleCheck.java

License:Open Source License

public static void main(String[] args) throws IOException {

    /*//from   www  .ja v  a2  s .  com
     * The ProfileCredentialsProvider will return your [default]
     * credential profile by reading from the credentials file located at
     * (/home/alok/.aws/credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider("default").getCredentials();
    } 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 (/home/alok/.aws/credentials), and is in valid format.", e);
    }

    AmazonS3 s3 = new AmazonS3Client(credentials);
    //        Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    Region usWest2 = Region.getRegion(Regions.AP_SOUTHEAST_1);
    s3.setRegion(usWest2);

    String bucketName = "alok-test";
    String key = "sample.json";

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

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
         */
        //            System.out.println("Creating bucket " + bucketName + "\n");
        //            s3.createBucket(bucketName);

        /*
         * List the buckets in your account
         */
        //            System.out.println("Listing buckets");
        //            for (Bucket bucket : s3.listBuckets()) {
        //                System.out.println(" - " + bucket.getName());
        //            }
        System.out.println();

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
         */
        System.out.println("Uploading a new object to S3 from a file\n");
        //s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
         */
        System.out.println("Downloading an object");
        //            S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        S3Object object = s3.getObject(new GetObjectRequest("alok-test", key));
        System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());

        /*
         * List objects in your bucket by prefix - There are many options for
         * listing the objects in your bucket.  Keep in mind that buckets with
         * many objects might truncate their results when listing their objects,
         * so be sure to check if the returned object listing is truncated, and
         * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
         * additional results.
         */
        System.out.println("Listing objects");
        ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
                //                    .withBucketName(bucketName)
                .withBucketName("alok-test"));
        //                    .withPrefix("My"));
        objectListing.getObjectSummaries().forEach((objectSummary) -> {
            System.out.println(
                    " - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
        });
        System.out.println();

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
         */
        //            System.out.println("Deleting an object\n");
        //            s3.deleteObject(bucketName, key);

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
         */
        //            System.out.println("Deleting bucket " + bucketName + "\n");
        //            s3.deleteBucket(bucketName);
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, 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());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}