List of usage examples for com.amazonaws AmazonServiceException getErrorCode
public String getErrorCode()
From source file:advanced.Requests.java
License:Open Source License
/** * Tag any of the resources we specify. * @param resources// w w w.j av a 2 s. c o m * @param tags */ private void tagResources(List<String> resources, List<Tag> tags) { // Create a tag request. CreateTagsRequest createTagsRequest = new CreateTagsRequest(); createTagsRequest.setResources(resources); createTagsRequest.setTags(tags); // Try to tag the Spot request submitted. try { ec2.createTags(createTagsRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error terminating instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } }
From source file:advanced.Requests.java
License:Open Source License
/** * The cleanup method will cancel and active requests and terminate any running instances * that were created using this object. *///from w w w .j a va2s.c om public void cleanup() { //==========================================================================// //================= Cancel/Terminate Your Spot Request =====================// //==========================================================================// try { // Cancel requests. System.out.println("Cancelling requests."); CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotInstanceRequestsRequest( spotInstanceRequestIds); ec2.cancelSpotInstanceRequests(cancelRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error cancelling instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } try { // Terminate instances. System.out.println("Terminate instances"); TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest(instanceIds); ec2.terminateInstances(terminateRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error terminating instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } // Delete all requests and instances that we have terminated. instanceIds.clear(); spotInstanceRequestIds.clear(); }
From source file:app.SQSMessage.java
License:Open Source License
public void sendmsg(Tweet t, String keyword) throws Exception { /*/*from www . j ava 2 s. c o m*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (). */ credentials = new ProfileCredentialsProvider("default").getCredentials(); AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("sending tweet to Queue"); System.out.println("===========================================\n"); try { // Send a message System.out.println("Sending a message to TweetQueue.\n"); JSONObject obj = new JSONObject(); obj.put("userId", t.getUserId() + ""); obj.put("lng", t.getLongitude() + ""); obj.put("lat", t.getLatitude() + ""); obj.put("text", t.getText()); // obj.put("time", t.getCreatedTime().toString()); obj.put("kwd", keyword); //String TwtJson = "{\"userId\":\"" + t.getUserId() + "\",\"lng\":\"" + t.getLongitude() + "\",\"lat\":\"" + t.getLatitude() + "\",\"text\":\"" + JSONObject.escape(t.getText()) + "\",\"time\":\"" + t.getCreatedTime() + "\",\"kwd\":\"" + keyword + "\"}"; String TwtJson = obj.toString(); System.out.println(TwtJson); sqs.sendMessage(new SendMessageRequest(q_url, TwtJson)); } 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:arcade.database.S3Connections.java
License:Open Source License
/** * Places an object into amazon bucket//from ww w.j a v a 2s . c o m * @param key (name) of file * @param filepath of file */ public void putFileIntoBucket(String key, String filepath) { File file = new File(filepath); try { myS3Instance.putObject(new PutObjectRequest(BUCKET_NAME, key, file)); } 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: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 .jav a 2 s . co 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 = "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.simpledb1.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { ArrayList<record> result = new ArrayList<record>(); AWSCredentials credentials = null;//from ww w. jav a 2 s.co 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()); } }
From source file:aws.sample.AmazonDynamoDBSample.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/* ww w . j a v a 2s . c o m*/ try { String tableName = "my-favorite-movies-table"; // Create a table with a primary key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema( new KeySchema(new KeySchemaElement().withAttributeName("name").withAttributeType("S"))) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(10L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active waitForTableToBecomeAvailable(tableName); // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); // Add an item Map<String, AttributeValue> item = newItem("Bill & Ted's Excellent Adventure", 1989, "****", "James", "Sara"); PutItemRequest putItemRequest = new PutItemRequest(tableName, item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Add another item item = newItem("Airplane", 1980, "*****", "James", "Billy Bob"); putItemRequest = new PutItemRequest(tableName, item); putItemResult = dynamoDB.putItem(putItemRequest); System.out.println("Result: " + putItemResult); // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); DeleteTableRequest deleteTableRequest = new DeleteTableRequest(tableName); dynamoDB.deleteTable(deleteTableRequest); System.out.println("Delete Table: "); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, 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) { ace.printStackTrace(); System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:aws.sample.AmazonDynamoDBSample.java
License:Open Source License
private static void waitForTableToBecomeAvailable(String tableName) { System.out.println("Waiting for " + tableName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try {/* w w w . ja va2 s . c om*/ Thread.sleep(1000 * 4); } catch (Exception e) { } try { DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(request).getTable(); String tableStatus = tableDescription.getTableStatus(); System.out.println(" - current state: " + tableStatus); if (tableStatus.equals(TableStatus.ACTIVE.toString())) return; } catch (AmazonServiceException ase) { if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false) throw ase; } } throw new RuntimeException("Table " + tableName + " never went active"); }
From source file:aws.sample.AwsConsoleApp.java
License:Open Source License
public static void main(String[] args) throws Exception { System.out.println("==========================================="); System.out.println("Welcome to the AWS Java SDK!"); System.out.println("==========================================="); init();//from w w w . ja v a 2 s .c o m /* * Amazon EC2 * * The AWS EC2 client allows you to create, delete, and administer instances programmatically. * * In this sample, we use an EC2 client to get a list of all the availability zones, and all instances sorted by reservation id. */ try { DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones(); System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones."); DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> instances = new HashSet<Instance>(); for (Reservation reservation : reservations) { instances.addAll(reservation.getInstances()); } System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running."); } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } /* * Amazon SimpleDB * * The AWS SimpleDB client allows you to query and manage your data stored in SimpleDB domains (similar to tables in a relational DB). * * In this sample, we use a SimpleDB client to iterate over all the domains owned by the current user, and add up the number of items (similar to rows of data in a relational DB) in each domain. */ try { ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100); ListDomainsResult sdbResult = sdb.listDomains(sdbRequest); int totalItems = 0; for (String domainName : sdbResult.getDomainNames()) { DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName); DomainMetadataResult domainMetadata = sdb.domainMetadata(metadataRequest); totalItems += domainMetadata.getItemCount(); } System.out.println("You have " + sdbResult.getDomainNames().size() + " Amazon SimpleDB domain(s)" + "containing a total of " + totalItems + " items."); } catch (AmazonServiceException ase) { System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } /* * Amazon S3 * * The AWS S3 client allows you to manage buckets and programmatically put and get objects to those buckets. * * In this sample, we use an S3 client to iterate over all the buckets owned by the current user, and all the object metadata in each bucket, to obtain a total object and space usage count. This is done without ever actually downloading a single object -- the requests work with object metadata only. */ try { List<Bucket> buckets = s3.listBuckets(); long totalSize = 0; int totalItems = 0; for (Bucket bucket : buckets) { /* * In order to save bandwidth, an S3 object listing does not contain every object in the bucket; after a certain point the S3ObjectListing is truncated, and further pages must be obtained with the AmazonS3Client.listNextBatchOfObjects() method. */ ObjectListing objects = s3.listObjects(bucket.getName()); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { totalSize += objectSummary.getSize(); totalItems++; } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); } System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s), " + "containing " + totalItems + " objects with a total size of " + totalSize + " bytes."); } catch (AmazonServiceException ase) { /* * AmazonServiceExceptions represent an error response from an AWS services, i.e. your request made it to AWS, but the AWS service either found it invalid or encountered an error trying to execute it. */ 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) { /* * AmazonClientExceptions represent an error that occurred inside the client on the local host, either while trying to send the request to AWS or interpret the response. For example, if no network connection is available, the client won't be able to connect to AWS to execute a request and will throw an AmazonClientException. */ System.out.println("Error Message: " + ace.getMessage()); } }
From source file:aws.sample.GettingStartedApp.java
License:Open Source License
public static void main(String[] args) throws Exception { System.out.println("==========================================="); System.out.println("Welcome to the AWS Java SDK!"); System.out.println("==========================================="); /*// ww w . j ava 2s . co m * Amazon EC2 * * The AWS EC2 client allows you to create, delete, and administer instances programmatically. * * In this sample, we use an EC2 client to submit a Spot request, wait for it to reach the active state, and then cancel and terminate the associated instance. */ try { // Setup the helper object that will perform all of the API calls. Requests requests = new Requests(); // Submit all of the requests. requests.submitRequests(); // Loop through all of the requests until all bids are in the active state // (or at least not in the open state). do { // Sleep for 60 seconds. Thread.sleep(SLEEP_CYCLE); } while (requests.areAnyOpen()); // Cancel all requests and terminate all running instances. requests.cleanup(); } catch (AmazonServiceException ase) { // Write out any exceptions that may have occurred. ase.printStackTrace(); System.out.println("Caught Exception: " + ase.getMessage()); System.out.println("Reponse Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }