List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:oulib.aws.s3.S3Util.java
public static AmazonS3 getS3Client() { AWSCredentials credentials = null;//from w w w . j av a 2 s. co m 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 (/Users/zhao0677/.aws/credentials), and is in valid format.", e); } AmazonS3 s3client = new AmazonS3Client(credentials); Region usEast = Region.getRegion(Regions.US_EAST_1); s3client.setRegion(usEast); return s3client; }
From source file:pa3.RemoteClientSQS.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 */// ww w. j a v a2 s . co m private static void initSQSandDynamoDB() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (C:\\Users\\HP\\.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 (C:\\Users\\HP\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); sqs.setRegion(usWest2); }
From source file:pa3.RemoteWorkerSQS.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. *//w w w . j ava 2s . c o m * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration */ private static void initSQSandDynamoDB() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (C:\\Users\\HP\\.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 (C:\\Users\\HP\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); sqs.setRegion(usWest2); }
From source file:pl.worker.Main.java
public static void putToSDB(String file) { AmazonSimpleDBClient simpleDB = new AmazonSimpleDBClient(); simpleDB.setRegion(Region.getRegion(Regions.US_WEST_2)); simpleDB.putAttributes(new PutAttributesRequest("leszczynska_project", "Przetworzono plik", Arrays.asList(new ReplaceableAttribute("key", file, Boolean.FALSE)))); }
From source file:producer.SensorReadingProducer.java
License:Open Source License
private void run(final int events, final OutputFormat format, final String streamName, final String region) throws Exception { AmazonKinesis kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain()); kinesisClient.setRegion(Region.getRegion(Regions.fromName(region))); int count = 0; SensorReading r = null;//from w w w. jav a2s. c o m do { r = nextSensorReading(format); try { PutRecordRequest req = new PutRecordRequest().withPartitionKey("" + rand.nextLong()) .withStreamName(streamName).withData(ByteBuffer.wrap(r.toString().getBytes())); kinesisClient.putRecord(req); } catch (ProvisionedThroughputExceededException e) { Thread.sleep(BACKOFF); } System.out.println(r); count++; } while (count < events); }
From source file:quicksell.galleryupload.Utils.S3Utils.java
License:Open Source License
/** * Gets an instance of a S3 client which is constructed using the given * Context.//from w w w.j a v a 2s .c om * * @param context An Context instance. * @return A default S3 client. */ public static AmazonS3Client getS3Client(Context context) { if (sS3Client == null) { sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext())); sS3Client.setRegion(Region.getRegion(Regions.fromName(S3Constants.BUCKET_REGION))); } return sS3Client; }
From source file:Reference.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/* w ww. jav a 2s .c o m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (). */ 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 (/Users/daniel/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); 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 MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String 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(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageRecieptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } 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()); } 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()); } }
From source file:S3Controller.DownloadingImages.java
public static void main(String[] args) throws IOException { AWSCredentials credentials = null;//from w w w . j ava 2 s .c o m String aws_access_key_id = "PUT_YOUR_aws_access_key_id_HERE"; String aws_secret_access_key = "PUT_YOUR_aws_secret_access_key_HERE"; try { credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);//.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 (~/.aws/credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region AP_SOUTHEAST_1 = Region.getRegion(Regions.AP_SOUTHEAST_1); s3.setRegion(AP_SOUTHEAST_1); String bucketName = "PUT_YOUR_S3-BUCKET-NAME_HERE"; String key = "PUT_YOUR_S3-BUCKET-KEY_HERE"; try { ArrayList arr = new ArrayList(); ArrayList EmailArray = new ArrayList(); Bucket bucket = new Bucket(bucketName); ObjectListing objects = s3.listObjects(bucket.getName()); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { // System.out.println(objectSummary.getKey() + "\t" + // objectSummary.getSize() + "\t" + // StringUtils.fromDate(objectSummary.getLastModified())); arr.add(objectSummary.getKey()); } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); KrakenIOExampleMain kraken = new KrakenIOExampleMain(); for (int i = 0; i < arr.size(); i++) { System.out.println("Compressing: " + arr.get(i)); String s = (String) arr.get(i); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket.getName(), s); System.out.println(s3.generatePresignedUrl(request)); URL Glink = s3.generatePresignedUrl(request); String Dlink = Glink.toString(); System.out.println("Download Link:" + Dlink); kraken.Compression(Dlink, bucketName); System.out.println("Compression completed: " + arr.get(i)); EmailArray.add("Processed Image:" + arr.get(i)); } System.out.println("Start Emailing list"); EmailSender esender = new EmailSender(); esender.EmailVerification(GetNotificationEmail, EmailArray); System.out.println("Kraken compression completed"); } 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()); } catch (ExecutionException ex) { Logger.getLogger(DownloadingImages.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(DownloadingImages.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:S3Controller.UploadImages.java
public void UploadToS3(String bucketname, String filename, String filepath) { // public static void main(String[] args) { AWSCredentials credentials = null;//from w w w. jav a2 s .c o m String aws_access_key_id = "PUT_YOUR_aws_access_key_id_HERE"; String aws_secret_access_key = "PUT_YOUR_aws_secret_access_key_HERE"; String bucketName = bucketname; //"zillionbucket"; String fileName = filename; //"javaee_duke_image.jpg"; String localpath = filepath; //"C:\\Users\\Hariom\\Documents\\NetBeansProjects\\JavaApplication9\\src\\ProcessedImages\\javaee_duke_image.jpg"; try { credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);//.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 (~/.aws/credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region AP_SOUTHEAST_1 = Region.getRegion(Regions.AP_SOUTHEAST_1); s3.setRegion(AP_SOUTHEAST_1); try { s3.putObject(new PutObjectRequest(bucketName, fileName, new File(localpath)) .withCannedAcl(CannedAccessControlList.PublicRead)); System.out.println("File Uploaded to S3: " + fileName); } 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:sample.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.PropertiesCredentials * @see com.amazonaws.ClientConfiguration */// www . ja va 2s . c o m private static void init() throws Exception { /* * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. */ dynamoDB = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); }