List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(String message, Throwable t)
From source file:com.netflix.edda.EddaElasticLoadBalancingClient.java
License:Apache License
public DescribeLoadBalancersResult describeLoadBalancers(DescribeLoadBalancersRequest request) { TypeReference<List<LoadBalancerDescription>> ref = new TypeReference<List<LoadBalancerDescription>>() { };/*w ww . j ava 2 s . c om*/ String url = config.url() + "/api/v2/aws/loadBalancers;_expand"; try { List<LoadBalancerDescription> loadBalancerDescriptions = parse(ref, doGet(url)); List<String> names = request.getLoadBalancerNames(); if (shouldFilter(names)) { List<LoadBalancerDescription> lbs = new ArrayList<LoadBalancerDescription>(); for (LoadBalancerDescription lb : loadBalancerDescriptions) { if (matches(names, lb.getLoadBalancerName())) lbs.add(lb); } loadBalancerDescriptions = lbs; } return new DescribeLoadBalancersResult().withLoadBalancerDescriptions(loadBalancerDescriptions); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.netflix.edda.EddaElasticLoadBalancingClient.java
License:Apache License
public DescribeLoadBalancerAttributesResult describeLoadBalancerAttributes( DescribeLoadBalancerAttributesRequest request) { validateNotEmpty("LoadBalancerName", request.getLoadBalancerName()); TypeReference<LoadBalancerAttributesView> ref = new TypeReference<LoadBalancerAttributesView>() { };// w ww .j a v a2 s . c o m String loadBalancerName = request.getLoadBalancerName(); String url = config.url() + "/api/v2/view/loadBalancerAttributes/" + loadBalancerName + ";_expand"; try { LoadBalancerAttributesView loadBalancerAttributesView = parse(ref, doGet(url)); return new DescribeLoadBalancerAttributesResult() .withLoadBalancerAttributes(loadBalancerAttributesView.getAttributes()); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.netflix.edda.EddaRoute53Client.java
License:Apache License
public ListHostedZonesResult listHostedZones(ListHostedZonesRequest request) { TypeReference<List<HostedZone>> ref = new TypeReference<List<HostedZone>>() { };//from w w w . j a v a2 s . c o m String url = config.url() + "/api/v2/aws/hostedZones;_expand"; try { List<HostedZone> hostedZones = parse(ref, doGet(url)); return new ListHostedZonesResult().withHostedZones(hostedZones); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.netflix.edda.EddaRoute53Client.java
License:Apache License
public ListResourceRecordSetsResult listResourceRecordSets(ListResourceRecordSetsRequest request) { validateNotEmpty("HostedZoneId", request.getHostedZoneId()); TypeReference<List<ResourceRecordSet>> ref = new TypeReference<List<ResourceRecordSet>>() { };// ww w. java 2 s . com String hostedZoneId = request.getHostedZoneId(); String url = config.url() + "/api/v2/aws/hostedRecords;_expand;zone.id=" + hostedZoneId; try { List<ResourceRecordSet> resourceRecordSets = parse(ref, doGet(url)); return new ListResourceRecordSetsResult().withResourceRecordSets(resourceRecordSets); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.pa3.cloudkon.remote.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. * */// w ww . j a v a 2s. c o m public static void init() { 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.prd.AmazonSESSample.java
License:Open Source License
public static void main(String[] args) throws IOException { // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content textBody = new Content().withData(BODY); Body body = new Body().withText(textBody); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);//w w w . j a va2s . c o m try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/Users/prabhjitsingh/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ 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/prabhjitsingh/.aws/credentials), and is in valid format.", e); } // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_EAST_1); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:com.rodosaenz.samples.aws.sqs.AwsSqsSimpleExample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//from www . j a va 2s .c om * 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 usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); String queue_name = "com-rodosaenz-examples-aws-sqs"; try { // Create a queue System.out.println("Creating a new SQS queue called " + queue_name + ".\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queue_name); 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 " + queue_name + ".\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); receiveMessageRequest.setMaxNumberOfMessages(1); 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 messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); //Get attributes GetQueueAttributesRequest request = new GetQueueAttributesRequest(myQueueUrl).withAttributeNames("All"); final Map<String, String> attributes = sqs.getQueueAttributes(request).getAttributes(); System.out.println(" Policy: " + attributes.get("Policy")); System.out.println(" MessageRetentionPeriod: " + attributes.get("MessageRetentionPeriod")); System.out.println(" MaximumMessageSize: " + attributes.get("MaximumMessageSize")); System.out.println(" CreatedTimestamp: " + attributes.get("CreatedTimestamp")); System.out.println(" VisibilityTimeout: " + attributes.get("VisibilityTimeout")); System.out.println(" QueueArn: " + attributes.get("QueueArn")); System.out.println(" ApproximateNumberOfMessages: " + attributes.get("ApproximateNumberOfMessages")); System.out.println(" ApproximateNumberOfMessagesNotVisible: " + attributes.get("ApproximateNumberOfMessagesNotVisible")); System.out.println(" DelaySeconds: " + attributes.get("DelaySeconds")); // 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:com.sag.tn.storm.stormmaven.main.Main.java
License:Open Source License
public static void main(String[] args) { AWSCredentials credentials = null;//w w w . j av a2 s . c o m try { credentials = new EnvironmentVariableCredentialsProvider().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); sqs.purgeQueue(new PurgeQueueRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>10</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>11</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>12</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>13</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>14</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>15</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>16</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>17</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>18</Value></PurchaseOrderRequest>")); sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", "<PurchaseOrderRequest><Value>19</Value></PurchaseOrderRequest>")); System.out.println("sent"); /* // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue"); for(int i = 0; i < 7; i++) { List<Message> messages = sqs.receiveMessage(receiveMessageRequest).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()); } sqs.deleteMessage(new DeleteMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", message.getReceiptHandle())); } }*/ /*MongoCredential credential = MongoCredential.createCredential("gergreg", "45345453", "34534fgalkej".toCharArray()); MongoClient mClient = new MongoClient(new ServerAddress("rgergerg", 33760), Arrays.asList(credential)); MongoDatabase db = mClient.getDatabase("5235235235"); MongoCollection<Document> coll = db.getCollection("35235325235");*/ /*MongoCursor<Document> cursor = coll.find(eq("rootTag", "IDataXMLCoder")).iterator(); while(cursor.hasNext()) { Document document = cursor.next(); System.out.println((String)document.get("docTypeId")); break; }*/ /*coll.updateOne(eq("docTypeId", "f0cf1e95-9406-44dc-930f-8de9aae8ccaf123"), new Document("$inc", new Document("execs", 100))); System.out.println("updated..."); mClient.close();*/ }
From source file:com.saife.sample.S3Sample.java
License:Apache License
/** * // w w w . ja v a 2s . co m */ private void initS3() { // S3 credential identity final String me = "john.curtis@saife-tiprnet"; AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider(me).getCredentials(); } catch (final 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/builder/.aws/credentials), and is in valid format.", e); } s3 = new AmazonS3Client(credentials); final Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); // define a bucket name bucketName = null; try { /* * List the buckets in your account */ for (final Bucket bucket : s3.listBuckets()) { if (bucket.getName().startsWith("saife-test-bucket")) { bucketName = bucket.getName(); System.out.println("Found Test Bucket:" + bucket.getName()); } } /* * Create a globally unique bucket name if needed. */ if (null == bucketName) { bucketName = "saife-test-bucket" + UUID.randomUUID(); System.out.println("Creating bucket " + bucketName + "\n"); s3.createBucket(bucketName); } } catch (final 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 (final 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()); } System.out.println("S3 services are enabled."); }
From source file:com.solomon.aws.service.AwsMailServ.java
public void sendMail() { Destination destination = new Destination().withToAddresses(new String[] { to }); Content subject = new Content().withData(topic); Content textBody = new Content().withData(body); Body mailBody = new Body().withText(textBody); Message message = new Message().withSubject(subject).withBody(mailBody); SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination) .withMessage(message);/*from w w w.jav a 2s .c om*/ try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [New US East (Virginia) Profile] * credential profile by reading from the credentials file located at * (/Users/zhao0677/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ try { AWSCredentials credentials = AwsUtil.getAwsCredentials(); AmazonSimpleEmailServiceClient client = AwsUtil.getAwsEmailServClient(credentials); Region REGION = Region.getRegion(AwsUtil.DEVELOPER_REGION); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } 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, and is in valid format.", e); } } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }