List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(String message, Throwable t)
From source file:EC2InstanceLaunch.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 *//* ww w.j av a2s. c om*/ private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/Users/hps/.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 (/Users/hps/.aws/credentials), and is in valid format.", e); } System.out.println("# Create Amazon Client object"); ec2 = new AmazonEC2Client(credentials); }
From source file:S3TransferProgressSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//from w ww.j a v a2s . c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/Users/zunzunwang/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ 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/zunzunwang/.aws/credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); 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:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Method to initialize the clients using the specified AWSCredentials. * * @param Exception//w w w .j av a 2 s . c om */ protected static void initClients() throws Exception { /* * 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); } // S3 client s3Client = new AmazonS3Client(credentials); Region s3Region = RegionUtils.getRegion(s3RegionName); s3Client.setRegion(s3Region); // Firehose client firehoseClient = new AmazonKinesisFirehoseClient(credentials); firehoseClient.setRegion(RegionUtils.getRegion(firehoseRegion)); // IAM client iamClient = new AmazonIdentityManagementClient(credentials); iamClient.setRegion(RegionUtils.getRegion(iamRegion)); }
From source file:SimpleQueueServiceMultiThread3.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/*from w w w . j av a 2s . 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,clientConfig); sqs = new AmazonSQSClient(credentials); Region apSouthEast1 = Region.getRegion(Regions.AP_SOUTHEAST_1); sqs.setRegion(apSouthEast1); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); //Define thread pool size ExecutorService executor = Executors.newFixedThreadPool(poolSize); //create a list to hold the Future object associated with Callable List<Future<Long>> list = new ArrayList<Future<Long>>(); //Create Callable instance Callable<Long> callable = new SimpleQueueServiceMultiThread3(); for (int i = 0; i < threadSize; i++) { //submit Callable tasks to be executed by thread pool Future<Long> future = executor.submit(callable); //add Future to the list, we can get return value using Future list.add(future); } for (Future<Long> fut : list) { try { // Future.get() waits for task to get completed System.out.println("Time difference : " + fut.get()); long timeDiff = fut.get().longValue(); totalTime = Long.valueOf(totalTime + timeDiff); if (timeDiff >= maxTime) { maxTime = timeDiff; } if (minTime == 0L && timeDiff >= minTime) { minTime = timeDiff; //}else if (timeDiff <= minTime && timeDiff != 0L) { } else if (timeDiff <= minTime) { minTime = timeDiff; } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } if (totalTime >= 0L) { averageTime = totalTime / threadSize; } System.out.println("Total Time : " + Long.valueOf(totalTime).toString()); System.out.println("Max Time : " + Long.valueOf(maxTime).toString()); System.out.println("Min Time : " + Long.valueOf(minTime).toString()); System.out.println("Average Time : " + Long.valueOf(averageTime).toString()); //shut down the executor service now executor.shutdown(); }
From source file:AmazonKinesisRecordProducerSample.java
License:Open Source License
private static void init() throws Exception { /*/*from w w w.ja v a 2 s .co m*/ * The ProfileCredentialsProvider will return your [haow2] * credential profile by reading from the credentials file located at * (/Users/Dawn/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("haow2").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/Dawn/.aws/credentials), and is in valid format.", e); } kinesis = new AmazonKinesisClient(credentials); }
From source file:receiveSQS.java
License:Open Source License
public static void main(String[] args) throws Exception { /*/* w ww. j av a 2 s.c o m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (). */ BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAI2ZCFS3NVEENXW5A", "tI/GgpSWDF/QrNVhtCRu1G+PX/10A2nJQH+yTOiv"); 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 usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // 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(); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl); System.out.println("Message size:"); //***************************************************** //For some reason, we only get one message at a time and it does not loop over. //***************************************************** //ReceiveMessageResponse receiveMessageResponse = amazonSQSClient.ReceiveMessage(receiveMessageRequest); 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()); String[] tweetdata = message.getBody().split("\\|\\|"); System.out.println(Arrays.toString(tweetdata)); System.out.println("Deleting a message.\n"); String messageRecieptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(queueUrl, messageRecieptHandle)); } } System.out.println(); /* // Delete a message // 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:amazon.dynamodb.config.GeoDataManager.java
License:Open Source License
/** * Query Amazon DynamoDB in parallel and filter the result. * * @param ranges A list of geohash ranges that will be used to query Amazon * DynamoDB./*w w w . java2 s .c o m*/ * * @param latLngRect The rectangle area that will be used as a reference * point for precise filtering. * * @return Aggregated and filtered items returned from Amazon DynamoDB. */ private GeoQueryResult dispatchQueries(List<GeoHashRango> ranges, GeoQueryRequest geoQueryRequest) { GeoQueryResult geoQueryResult = new GeoQueryResult(); ExecutorService executorService = config.getExecutorService(); List<Future<?>> futureList = new ArrayList<Future<?>>(); for (GeoHashRango outerRange : ranges) { for (GeoHashRango range : outerRange.trySplit(config.getHashKeyLength())) { GeoQueryThread geoQueryThread = new GeoQueryThread(geoQueryRequest, geoQueryResult, range); futureList.add(executorService.submit(geoQueryThread)); } } ranges = null; for (int i = 0; i < futureList.size(); i++) { try { futureList.get(i).get(); } catch (Exception e) { for (int j = i + 1; j < futureList.size(); j++) { futureList.get(j).cancel(true); } throw new AmazonClientException("Querying Amazon DynamoDB failed.", e); } } futureList = null; return geoQueryResult; }
From source file:assign1.simpledb.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null;/*from w w w .ja v a2 s .c om*/ try { credentials = new PropertiesCredentials( simpledb.class.getResourceAsStream("AwsCredentials.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/huanglin/.aws/credentials), and is in valid format.", e); } AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); try { String myDomain = "MyStore"; String selectExpression = "select count(*) from " + myDomain + " where content like '%news%'"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); for (Item item : sdb.select(selectRequest).getItems()) { System.out.println(" itemIndex: " + item.getName()); for (Attribute attribute : item.getAttributes()) { System.out.println(" Attribute"); System.out.println(" Name: " + attribute.getName()); System.out.println(" Value: " + attribute.getValue()); } } } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, 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 SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:assign1.simpledb.java
License:Open Source License
public List<record> query(String word) throws Exception { /*/*from w w w. j a v a 2 s . c o m*/ * 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*/ ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null; try { credentials = new PropertiesCredentials( simpledb.class.getResourceAsStream("AwsCredentials.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/huanglin/.aws/credentials), and is in valid format.", e); } AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); String myDomain = "MyStore"; String filter = word; String nextToken = null; SelectResult selectResult = null; do { String selectExpression = ""; if (word.equals("all")) selectExpression = "select * from MyStore LIMIT 2500"; else selectExpression = "select * from " + myDomain + " where content like '%" + filter + "%' LIMIT 2500"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); selectRequest.setNextToken(nextToken); selectResult = sdb.select(selectRequest); nextToken = selectResult.getNextToken(); List<Item> list = selectResult.getItems(); for (Item item : list) { System.out.println(" itemIndex: " + item.getName()); List<Attribute> attributeTmp = new ArrayList<Attribute>(); attributeTmp = item.getAttributes(); record tmp = new record(); for (int i = 0; i < 5; i++) { if (attributeTmp.get(i).getName().equals("content")) tmp.content = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("geoLat")) tmp.x = Double.parseDouble(attributeTmp.get(i).getValue()); else if (attributeTmp.get(i).getName().equals("Username")) tmp.username = attributeTmp.get(i).getValue(); else if (attributeTmp.get(i).getName().equals("Location")) tmp.location = attributeTmp.get(i).getValue(); else tmp.y = Double.parseDouble(attributeTmp.get(i).getValue()); } result.add(tmp); } } while (nextToken != null); return result; }
From source file:assign1.simpledb1.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null;/* w w w.j a v a 2 s.c o m*/ try { credentials = new PropertiesCredentials( simpledb.class.getResourceAsStream("AwsCredentials.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/huanglin/.aws/credentials), and is in valid format.", e); } AmazonSimpleDB sdb = new AmazonSimpleDBClient(credentials); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SimpleDB"); System.out.println("===========================================\n"); try { String myDomain = "Twitter"; String selectExpression = "select count(*) from " + myDomain + " where content like '%news%'"; System.out.println("Selecting: " + selectExpression + "\n"); SelectRequest selectRequest = new SelectRequest(selectExpression); for (Item item : sdb.select(selectRequest).getItems()) { System.out.println(" itemIndex: " + item.getName()); for (Attribute attribute : item.getAttributes()) { System.out.println(" Attribute"); System.out.println(" Name: " + attribute.getName()); System.out.println(" Value: " + attribute.getValue()); } } } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, 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 SimpleDB, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }