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.brighttag.agathon.security.ec2.Ec2SecurityGroupModule.java

License:Apache License

@Provides
@Singleton//from ww  w  .ja  va2 s .  c om
@Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY)
Map<String, Region> provideRegions() {
    ImmutableMap.Builder<String, Region> regionMap = ImmutableMap.builder();
    for (Regions region : Regions.values()) {
        // On first call, this makes a network request to fetch the metadata for all regions
        regionMap.put(region.getName(), Region.getRegion(region));
    }
    return regionMap.build();
}

From source file:com.bye.project.S3TransferProgressSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*  w w  w.ja  v  a2  s .c  o m*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * TransferManager manages a pool of threads, so we create a
     * single instance and share it throughout our application.
     */
    AmazonS3 s3 = new AmazonS3Client(credentials = new PropertiesCredentials(
            S3TransferProgressSample.class.getResourceAsStream("AwsCredentials.properties")));
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);
    tx = new TransferManager(s3);

    bucketName = "s3-upload-sdk-sample-" + credentials.getAWSAccessKeyId().toLowerCase();

    new S3TransferProgressSample();
}

From source file:com.cloud.Assignment.QueueSender.java

License:Open Source License

public boolean sendToQueue(String queue, String message) throws Exception {
    Properties props = new Properties();
    AWSCredentials credentials = null;/* ww w . j a  v a2 s .  c om*/
    String myQueueUrl = null;
    System.out.println("Queue :" + queue + " Message :" + message);
    try {
        credentials = new ClasspathPropertiesFileCredentialsProvider("AwsCredentials.properties")
                .getCredentials();
        ClassLoader loader = Thread.currentThread().getContextClassLoader();

        props.load(loader.getResourceAsStream("/QueueURL.properties"));
    } 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/prabhus/.aws/credentials), and is in valid format.", e);
    }
    AmazonSQS sqs = new AmazonSQSClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_EAST_1);
    sqs.setRegion(usWest2);

    try {
        myQueueUrl = props.getProperty(queue);
        System.out.println("URL :" + myQueueUrl);
        System.out.println("Sending " + message);
        sqs.sendMessage(new SendMessageRequest(myQueueUrl, message));
        isMessagePosted = true;
    } catch (AmazonServiceException ase) {

        throw new AmazonServiceException("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon SQS, but was rejected with an error response for some reason.");

    } catch (AmazonClientException ace) {
        System.out.println("Error Message: " + ace.getMessage());
        throw new AmazonClientException("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.");

    }
    return isMessagePosted;
}

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSCloud.java

License:Open Source License

public static Region getRegion(String regionName) {
    if (StringUtils.isNotEmpty(regionName)) {
        return RegionUtils.getRegion(regionName);
    } else {/*from www.j  a v a2  s  .c  o m*/
        return Region.getRegion(Regions.US_EAST_1);
    }
}

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java

License:Open Source License

Region getRegion(String regionName) {
    if (StringUtils.isNotEmpty(regionName)) {
        return RegionUtils.getRegion(regionName);
    } else {/* w  w  w .  ja va 2s.  c  o  m*/
        return Region.getRegion(Regions.US_EAST_1);
    }
}

From source file:com.clouddrive.parth.AmazonOperations.java

public AmazonOperations() {
    String secretKey = "kxDFnyETb02UrLr4YT3bRjiET+/FNGUMrE3DrU4j";
    String accessKey = "AKIAII3DXT3OYD5UV4WQ";

    BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);
    s3 = new AmazonS3Client(awsCreds);

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

From source file:com.clouddrive.parth.NewClass.java

public static void init(String instanceType, String noOfinstances) throws Exception {
    INSTANCE_COUNT = Integer.parseInt(noOfinstances);
    switch (instanceType) {
    case "C1Medium":
        INSTANCE_TYPE = InstanceType.C1Medium.toString();
        break;/*w w  w .  j  av a  2 s .  com*/
    case "C1Xlarge":
        INSTANCE_TYPE = InstanceType.C1Xlarge.toString();
        break;
    case "C32xlarge":
        INSTANCE_TYPE = InstanceType.C32xlarge.toString();
        break;
    case "C34xlarge":
        INSTANCE_TYPE = InstanceType.C34xlarge.toString();
        break;
    case "C38xlarge":
        INSTANCE_TYPE = InstanceType.C38xlarge.toString();
        break;
    case "C3Large":
        INSTANCE_TYPE = InstanceType.C3Large.toString();
        break;
    case "C3Xlarge":
        INSTANCE_TYPE = InstanceType.C3Xlarge.toString();
        break;
    case "Cc14xlarge":
        INSTANCE_TYPE = InstanceType.Cc14xlarge.toString();
        break;
    case "Cc28xlarge":
        INSTANCE_TYPE = InstanceType.Cc28xlarge.toString();
        break;
    case "Cg14xlarge":
        INSTANCE_TYPE = InstanceType.Cg14xlarge.toString();
        break;
    case "Cr18xlarge":
        INSTANCE_TYPE = InstanceType.Cr18xlarge.toString();
        break;
    case "G22xlarge":
        INSTANCE_TYPE = InstanceType.G22xlarge.toString();
        break;
    case "T1Micro":
        INSTANCE_TYPE = InstanceType.T1Micro.toString();
        break;

    }

    //AWSCredentials credentials = new PropertiesCredentials(NewClass.class.getClassLoader().getResourceAsStream(
    //   "AwsCredentials.properties"));
    // s3 = new AmazonS3Client(credentials);
    String secretKey = "kxDFnyETb02UrLr4YT3bRjiET+/FNGUMrE3DrU4j";
    String accessKey = "AKIAII3DXT3OYD5UV4WQ";

    BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);
    s3 = new AmazonS3Client(awsCreds);

    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    ((AmazonWebServiceClient) s3).setRegion(usWest2);
    emr = new AmazonElasticMapReduceClient(awsCreds);
    emr.setRegion(Region.getRegion(Regions.EU_WEST_1));
}

From source file:com.cloudkon.remote.worker.Dynamodb.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
 *///from  ww  w  .j a v  a  2 s.  com
public static void init() {
    /*
     * Load the credentials
     */
    AWSCredentials credentials = null;
    try {
        //InputStream credentialsFile = Dynamodb.class.getResourceAsStream("awsSecuCredentials.properties");
        InputStream credentialsFile = new FileInputStream("./awsSecuCredentials.properties");
        credentials = new PropertiesCredentials(credentialsFile);
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential file. ", e);
    }
    dynamoDB = new AmazonDynamoDBClient(credentials);
    Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    dynamoDB.setRegion(usEast1);
}

From source file:com.crickdata.upload.s3.UploadLiveData.java

License:Open Source License

public Map<String, Date> uploadToS3(String fileName, boolean type) throws IOException {

    Statistics statistics = new Statistics();
    Map<String, Date> perfMap = new HashMap<String, Date>();
    AWSCredentials credentials = null;//from ww w .  ja  va 2s.co m
    try {
        credentials = new BasicAWSCredentials("AKIAI6QKTRAQE7MXQOIQ",
                "wIG6u1yI5ZaseeJbvYSUmD98qelIJNSCVBzt5k2q");
    } 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 (C:\\Users\\bssan_000\\.aws\\credentials), and is in valid format.", e);
    }

    AmazonS3 s3 = new AmazonS3Client(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);
    String bucketName;
    if (!type)
        bucketName = "cricmatchinfo";
    else
        bucketName = "cricmatchinfoseries";
    String key = fileName.replace(".json", "").trim();
    try {
        perfMap.put("S3INSERTREQ", new Date());
        statistics.setS3Req(new Date());
        File f = readMatchFile(fileName);

        double bytes = f.length();
        double kilobytes = (bytes / 1024);
        System.out.println("Details :" + kilobytes);
        s3.putObject(new PutObjectRequest(bucketName, key, f));
        statistics.setSize(String.valueOf(kilobytes));

        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        perfMap.put("S3SAVERES", object.getObjectMetadata().getLastModified());
        statistics.setKey(key);
        statistics.setS3Res(object.getObjectMetadata().getLastModified());
        MyUI.stats.add(statistics);

        displayTextInputStream(object.getObjectContent());

        ObjectListing objectListing = s3
                .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My"));
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(
                    " - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
        }
    } 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());
    }
    return perfMap;
}

From source file:com.dannyofir.www.overdarevideorecorder.MainActivity.java

public void setAmazonS3Client(CognitoCachingCredentialsProvider credentialsProvider) {

    // Create an S3 client
    amazonS3Client = new AmazonS3Client(credentialsProvider);

    // Set the region of your S3 bucket
    amazonS3Client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1));

}