List of usage examples for com.amazonaws.regions Region getRegion
public static Region getRegion(Regions region)
From source file:squash.booking.lambdas.core.OptimisticPersister.java
License:Apache License
@Override public final void initialise(int maxNumberOfAttributes, LambdaLogger logger) throws Exception { if (initialised) { throw new IllegalStateException("The optimistic persister has already been initialised"); }// ww w. ja va 2 s . c o m this.logger = logger; simpleDbDomainName = getEnvironmentVariable("SimpleDBDomainName"); versionAttributeName = "VersionNumber"; this.maxNumberOfAttributes = maxNumberOfAttributes; region = Region.getRegion(Regions.fromName(getEnvironmentVariable("AWS_REGION"))); initialised = true; }
From source file:squash.booking.lambdas.core.PageManager.java
License:Apache License
@Override public void initialise(IBookingManager bookingManager, ILifecycleManager lifecycleManager, LambdaLogger logger) throws Exception { this.logger = logger; websiteBucketName = getEnvironmentVariable("WebsiteBucket"); adminSnsTopicArn = getEnvironmentVariable("AdminSNSTopicArn"); region = Region.getRegion(Regions.fromName(getEnvironmentVariable("AWS_REGION"))); this.bookingManager = bookingManager; this.lifecycleManager = lifecycleManager; initialised = true;/* www.jav a 2 s .c om*/ }
From source file:squash.booking.lambdas.core.RuleManager.java
License:Apache License
@Override public final void initialise(IBookingManager bookingManager, ILifecycleManager lifecycleManager, LambdaLogger logger) throws Exception { if (initialised) { throw new IllegalStateException("The rule manager has already been initialised"); }/*from w w w .j av a 2 s .c o m*/ this.bookingManager = bookingManager; this.lifecycleManager = lifecycleManager; this.logger = logger; ruleItemName = "BookingRulesAndExclusions"; this.optimisticPersister = getOptimisticPersister(); optimisticPersister.initialise(maxNumberOfRules, logger); adminSnsTopicArn = getEnvironmentVariable("AdminSNSTopicArn"); region = Region.getRegion(Regions.fromName(getEnvironmentVariable("AWS_REGION"))); initialised = true; }
From source file:support.SQS.java
License:Open Source License
SQS() { try {//from w w w. j a va2 s .co m credentials = new ProfileCredentialsProvider(key_path, "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\\Sayon\\.aws\\credentials), and is in valid format.", e); } ClientConfiguration clientConfiguration = new ClientConfiguration(); // clientConfiguration.setProxyHost(proxy_host); // clientConfiguration.setProxyPort(proxy_port); // clientConfiguration.setProxyUsername(proxy_username); // clientConfiguration.setProxyPassword(proxy_password); // sqs = new AmazonSQSClient(credentials, clientConfiguration); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); }
From source file:test1.SimpleQueueServiceSample.java
License:Open Source License
public static AmazonSQS init() { AWSCredentials credentials = null;/*from w w w . j a va 2s . c o m*/ try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException(e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); return sqs; }
From source file:ti.aws.S3TransferManagerProxy.java
License:Open Source License
@Kroll.method public void upload(KrollDict params) { if (credentialsProvider == null) { Log.e(LCAT, "Missing credentials provider! Please use 'configure(args)' before."); return;// w w w.j ava 2s. co m } final String file = params.getString("file"); final String bucket = params.getString("bucket"); final String key = params.getString("key"); final KrollFunction success = (KrollFunction) params.get("success"); final KrollFunction error = (KrollFunction) params.get("error"); Context appContext = TiApplication.getInstance(); if (appContext == null) return; AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider); s3Client.setRegion(Region.getRegion(Regions.fromName("eu-central-1"))); TransferUtility transferUtility = TransferUtility.builder().context(appContext) .awsConfiguration(AWSMobileClient.getInstance().getConfiguration()) .s3Client(new AmazonS3Client(AWSMobileClient.getInstance().getCredentialsProvider())).build(); File nativeFile = new File(Uri.parse(file).getPath()); TransferObserver uploadObserver = transferUtility.upload(key, nativeFile); uploadObserver.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id, TransferState state) { KrollObject krollObject = getKrollObject(); if (krollObject == null) { return; } if (TransferState.COMPLETED == state) { KrollDict event = new KrollDict(); event.put("body", key); success.callAsync(krollObject, event); } } @Override public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { } @Override public void onError(int id, Exception ex) { KrollObject krollObject = getKrollObject(); if (krollObject == null) { return; } KrollDict event = new KrollDict(); event.put("error", ex.getMessage()); error.callAsync(krollObject, event); } }); }
From source file:twitter.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/*from w w w.j a v a 2 s . c o m*/ * 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(); } 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); } 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(); System.out.println("queueUrl is:" + myQueueUrl); // 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"); String id = "2"; String tweet = "I am hungry"; String workRequest = "{" + " \"id\": \"" + id + "\"," + " \"tweet\": \"" + tweet + "\"" + "}"; sqs.sendMessage(new SendMessageRequest().withQueueUrl(myQueueUrl).withMessageBody(workRequest)); // 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(); Thread.sleep(5000); String id2 = "3"; String t = "yes,it is"; String workRequest1 = "{" + " \"id\": \"" + id2 + "\"," + " \"tweet\": \"" + t + "\"" + "}"; sqs.sendMessage(new SendMessageRequest().withQueueUrl(myQueueUrl).withMessageBody(workRequest1)); ReceiveMessageRequest receiveMessageRequest1 = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest1).getMessages(); System.out.println("!!!!!" + messages.size()); 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:uk.co.jassoft.email.EmailSenderService.java
public void send(String recipientAddress, String subject, Map emailContent) throws EmailSendException { try {/*from w ww . j a v a 2 s . c om*/ if (System.getenv("API_SEND_EMAILS").equals("false")) { LOG.info("API_SEND_EMAILS is set to [{}]", System.getenv("API_SEND_EMAILS")); return; } // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(recipientAddress); // Create the subject and body of the message. Content subjectContent = new Content().withData(subject); Body body = new Body(); if (template != null) body = body.withText(new Content().withData(VelocityEngineUtils .mergeTemplateIntoString(velocityEngine, template, "UTF-8", emailContent))); if (htmlTemplate != null) body = body.withHtml(new Content().withData(VelocityEngineUtils .mergeTemplateIntoString(velocityEngine, htmlTemplate, "UTF-8", emailContent))); // Create a message with the specified subject and body. Message message = new Message().withSubject(subjectContent).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(fromAddress).withDestination(destination) .withMessage(message); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient( new EnvironmentVariableCredentialsProvider()); Region REGION = Region.getRegion(Regions.EU_WEST_1); client.setRegion(REGION); // Send the email. client.sendEmail(request); } catch (Exception exception) { throw new EmailSendException(exception.getMessage(), exception); } }
From source file:uk.co.keithj.postcodelookup.infrastructure.repository.SpringDataDynamoDBConfigurator.java
License:Apache License
@Bean public Region amazonRegion() { return Region.getRegion(Regions.fromName(amazonRegion)); }
From source file:upload.s3.S3TransferProgressSample.java
License:Open Source License
public S3TransferProgressSample(File file) throws Exception { AmazonS3 s3 = new AmazonS3Client( credentials = new ClasspathPropertiesFileCredentialsProvider().getCredentials()); Region usWest2 = Region.getRegion(Regions.EU_WEST_1); s3.setRegion(usWest2);//w w w. java 2 s. co m tx = new TransferManager(s3); bucketName = "test-s3-sqs"; createAmazonS3Bucket(); PutObjectRequest request = new PutObjectRequest(bucketName, file.getName(), file) .withCannedAcl(CannedAccessControlList.PublicRead); upload = tx.upload(request); }