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.example.rafa.myapplication.AmazonClientManager.java

License:Open Source License

private void initClients() {
    /****credentials***/
    BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAIFAXGBW3HDEGKF2Q",
            "AIaVirpRfFkwAyuqN38OviapQTGAZnVOPtB1Pg6G");
    ddb = new AmazonDynamoDBClient(credentials);

    // Amazon Database
    ddb.setRegion(Region.getRegion(Regions.US_EAST_1));

    // Local Database
    //ddb.setEndpoint("http://192.168.0.19:8000");
}

From source file:com.exedosoft.plat.storage.s3.S3Sample.java

License:Open Source License

public static void main(String[] args) throws IOException {
    /*//from w ww .jav a  2 s .com
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonS3 s3 = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

    String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String key = "MyObjectKey";

    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()));

        /*
         * 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));
        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).withPrefix("My"));
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            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());
    }
}

From source file:com.experiment.trax.services.AWSClientManager.java

License:Open Source License

private void initClients() {
    AWSCredentials credentials = AWSSharedPreferencesWrapper
            .getCredentialsFromSharedPreferences(this.sharedPreferences);

    Region region = Region.getRegion(Regions.US_EAST_1);

    //        s3Client = new AmazonS3Client( credentials );
    //       s3Client.setRegion(region);
    ////from   ww  w  . ja va2  s.  c o m
    //       sqsClient = new AmazonSQSClient( credentials );
    //       sqsClient.setRegion(region);

    sdbClient = new AmazonSimpleDBClient(credentials);
    sdbClient.setRegion(region);

    //       snsClient = new AmazonSNSClient( credentials );
    //       snsClient.setRegion(region);
}

From source file:com.facebook.presto.dynamodb.DynamodbConfig.java

License:Apache License

public Region getAWSRegion() {
    return Region.getRegion(region == null ? Regions.DEFAULT_REGION : Regions.fromName(region));
}

From source file:com.facebook.presto.rakam.S3BackupConfig.java

License:Apache License

public Region getAWSRegion() {
    return Region.getRegion(region == null ? DEFAULT_REGION : Regions.fromName(region));
}

From source file:com.github.gregwhitaker.sns.Consumer.java

License:Apache License

public Consumer(String name, String queueArn) {
    this.name = name;
    this.queueArn = queueArn;
    this.sqsClient = new AmazonSQSClient(new DefaultAWSCredentialsProviderChain());
    this.sqsClient.setRegion(Region.getRegion(Regions.US_WEST_2));
}

From source file:com.github.gregwhitaker.sns.Producer.java

License:Apache License

public Producer(String name, String topicArn) {
    this.name = name;
    this.topicArn = topicArn;
    this.snsClient = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain());
    this.snsClient.setRegion(Region.getRegion(Regions.US_WEST_2));
}

From source file:com.github.sdmcraft.slingdynamo.demo.App.java

License:Open Source License

/**
 * Inits the./*from  w  w w .  ja  v a2  s  . c om*/
 */
public static void init() {
    Scanner reader = new Scanner(System.in);
    System.out.println("Enter access key:");

    accessKey = reader.next();
    System.out.println("Enter secret access key:");

    secretAccessKey = reader.next();
    System.out.println("Access Key:" + accessKey);
    System.out.println("Secret access Key:" + secretAccessKey);

    reader.close();

    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretAccessKey);
    dynamoDB = new AmazonDynamoDBClient(awsCredentials);

    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    dynamoDB.setRegion(usWest2);
}

From source file:com.github.sdmcraft.slingdynamo.impl.DynamoDBResourceProviderFactory.java

License:Open Source License

/**
 * Activate./*from w w w.  jav a 2  s  .c om*/
 *
 * @param context the context
 * @param config the config
 */
@Activate
protected void activate(BundleContext context, Map<String, Object> config) {
    this.root = PropertiesUtil.toString(config.get(ResourceProvider.ROOTS), DEFAULT_ROOT);

    if ((this.root == null) || this.root.isEmpty()) {
        this.root = DEFAULT_ROOT;
    }

    this.resourceType = PropertiesUtil.toString(config.get(SlingConstants.PROPERTY_RESOURCE_TYPE),
            Constants.DEFAULT_GET_SERVLET);

    if ((this.resourceType == null) || this.resourceType.isEmpty()) {
        this.resourceType = Constants.DEFAULT_GET_SERVLET;
    }

    dynamoDBClient = new AmazonDynamoDBClient(awsCredentialsProvider.getCredentials());

    this.region = PropertiesUtil.toString(config.get(PROP_REGION), Constants.DEFAULT_REGION);

    if ((this.region != null) && !this.region.isEmpty()) {
        Region awsRegion = Region.getRegion(Regions.fromName(region));
        dynamoDBClient.setRegion(awsRegion);
    }

    this.endpoint = PropertiesUtil.toString(config.get(PROP_ENDPOINT), Constants.DEFAULT_ENDPOINT);

    if ((this.endpoint != null) && !this.endpoint.isEmpty()) {
        dynamoDBClient.setEndpoint(this.endpoint);
    }

    dynamoDB = new DynamoDB(dynamoDBClient);
}

From source file:com.github.sporcina.mule.modules.DynamoDBConnector.java

License:Open Source License

/**
 * Connect to the DynamoDB service//from  w  w w .  j  av a2  s  .c o m
 *
 * @param accessKey
 *         the access key provided to you through your Amazon AWS account
 * @param secretKey
 *         the secret key provided to you through your Amazon AWS account
 */
@Connect
// TODO: try this => @Default (value = Query.MILES) @Optional String unit
public void connect(@ConnectionKey String accessKey, String secretKey) throws ConnectionException {

    if (StringUtils.isNotEmpty(accessKey) && StringUtils.isNotEmpty(secretKey)) {
        createDynamoDBClient(accessKey, secretKey);
    } else {
        createDynamoDBClient();
    }

    Region regionEnum = Region.getRegion(getRegionAsEnum());
    getDynamoDBClient().setRegion(regionEnum);
}