Example usage for com.amazonaws AmazonServiceException getMessage

List of usage examples for com.amazonaws AmazonServiceException getMessage

Introduction

In this page you can find the example usage for com.amazonaws AmazonServiceException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:NYSELoad.java

License:Open Source License

private static void readAndLoad(String tableName, String nysePath) {
    try {/*from  w w  w. j av  a2s.  c  o m*/
        // Create table if it does not exist yet
        if (!Tables.doesTableExist(dynamoDB, tableName)) {
            System.out.println("Table " + tableName + " is does not exist");
        }

        File localInputFolder = new File(nysePath);
        File[] listOfDirectories = localInputFolder.listFiles();
        for (File dir : listOfDirectories) {
            if (dir.isDirectory()) {
                File[] files = dir.listFiles();
                for (File file : files) {
                    BufferedReader br = null;
                    if (file.getName().endsWith("csv")) {
                        // Add an item
                        String sCurrentLine;

                        try {
                            br = new BufferedReader(new FileReader(file));
                            while ((sCurrentLine = br.readLine()) != null) {
                                nyseParser.parse(sCurrentLine);
                                Map<String, AttributeValue> item = newItem(nyseParser);
                                putItem(tableName, item);
                            }
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    } 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) {
        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:SimpleDBExample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*//from   ww  w.  ja v  a2  s  .co m
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * 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
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sdb.setRegion(usWest2);

    System.out.println("===========================================");
    System.out.println("Getting Started with Amazon SimpleDB");
    System.out.println("===========================================\n");

    try {
        // Create a domain
        String myDomain = "MyStore";
        System.out.println("Creating domain called " + myDomain + ".\n");
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        System.out.println("Listing all domains in your account:\n");
        for (String domainName : sdb.listDomains().getDomainNames()) {
            System.out.println("  " + domainName);
        }
        System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createSampleData()));

        // Select data from a domain
        // Notice the use of backticks around the domain name in our select expression.
        String selectExpression = "select * from `" + myDomain + "` where Category = 'Clothes'";
        System.out.println("Selecting: " + selectExpression + "\n");
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        for (Item item : sdb.select(selectRequest).getItems()) {
            System.out.println("  Item");
            System.out.println("    Name: " + item.getName());
            for (Attribute attribute : item.getAttributes()) {
                System.out.println("      Attribute");
                System.out.println("        Name:  " + attribute.getName());
                System.out.println("        Value: " + attribute.getValue());
            }
        }
        System.out.println();

        // Delete values from an attribute
        System.out.println("Deleting Blue attributes in Item_O3.\n");
        Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        sdb.deleteAttributes(
                new DeleteAttributesRequest(myDomain, "Item_03").withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        System.out.println("Deleting attribute Year in Item_O3.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
                .withAttributes(new Attribute().withName("Year")));

        // Replace an attribute
        System.out.println("Replacing Size of Item_03 with Medium.\n");
        List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));

        // Delete an item and all of its attributes
        System.out.println("Deleting Item_03.\n");
        sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));

        // Delete a domain
        System.out.println("Deleting " + myDomain + " domain.\n");
        sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } 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:S3Sample.java

License:Open Source License

public static void main2(String[] args) throws IOException {
    /*/*  w w w . j  a va2s .  c  om*/
     * 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
     */
    AmazonS3 s3 = new AmazonS3Client(
            new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties")));

    //String bucketName = "my-first-s3-bucket-" + UUID.randomUUID();
    String bucketName = "ringtone_image";
    String key = "test";

    System.out.println("being...");
    System.out.println("size:");
    System.out.println("end.\n");

    try {
        /*
         * Create a new S3 bucket - Amazon S3 bucket names are globally unique,
         * so once a bucket name has been taken by any user, you can't create
         * another bucket with that same name.
         *
         * You can optionally specify a location for your bucket if you want to
         * keep your data closer to your applications or users.
                
        System.out.println("Creating bucket " + bucketName + "\n");
        s3.createBucket(bucketName);
         */

        /*
         * List the buckets in your account
                 
        System.out.println("Listing buckets");
        for (Bucket bucket : s3.listBuckets()) {
        System.out.println(" - " + bucket.getName());
        }
        System.out.println();
         */

        /*
         * Upload an object to your bucket - You can easily upload a file to
         * S3, or upload directly an InputStream if you know the length of
         * the data in the stream. You can also specify your own metadata
         * when uploading to S3, which allows you set a variety of options
         * like content-type and content-encoding, plus additional metadata
         * specific to your applications.
                
        System.out.println("Uploading a new object to S3 from a file\n");
        s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile()));         
        */

        /*
         * Download an object - When you download an object, you get all of
         * the object's metadata and a stream from which to read the contents.
         * It's important to read the contents of the stream as quickly as
         * possibly since the data is streamed directly from Amazon S3 and your
         * network connection will remain open until you read all the data or
         * close the input stream.
         *
         * GetObjectRequest also supports several other options, including
         * conditional downloading of objects based on modification times,
         * ETags, and selectively downloading a range of an object.
                
                
        System.out.println("Downloading an object");
        S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
        System.out.println("Content-Type: "  + object.getObjectMetadata().getContentType());
        displayTextInputStream(object.getObjectContent());
         */

        /*
         * List objects in your bucket by prefix - There are many options for
         * listing the objects in your bucket.  Keep in mind that buckets with
         * many objects might truncate their results when listing their objects,
         * so be sure to check if the returned object listing is truncated, and
         * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve
         * additional results.
                
                
                
        System.out.println("Listing objects");
                
        ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
            .withBucketName(bucketName)
            .withPrefix("My"));
                
                
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
        System.out.println(" - " + objectSummary.getKey() + "  " +
                           "(size = " + objectSummary.getSize() + ")");
                   
        }
        */

        /*
         * Delete an object - Unless versioning has been turned on for your bucket,
         * there is no way to undelete an object, so use caution when deleting objects.
                
                
        System.out.println("Deleting an object\n");
        s3.deleteObject(bucketName, key);
         */

        /*
         * Delete a bucket - A bucket must be completely empty before it can be
         * deleted, so remember to delete any objects from your buckets before
         * you try to delete them.
                
                
        System.out.println("Deleting bucket " + bucketName + "\n");
        s3.deleteBucket(bucketName);
         */
    } 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: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("===========================================");

    /*// w w w . j a  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 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.
        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());
    }
}

From source file:whgHelper.java

License:Open Source License

public static void errorMessagesAse(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());
}

From source file:AwsSdkSample.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 .  j  a va 2  s.c o m

    try {
        /*
         * The Amazon EC2 client allows you to easily launch and configure
         * computing capacity in AWS datacenters.
         *
         * In this sample, we use the EC2 client to list the availability zones
         * in a region, and then list the instances running in those zones.
         */
        DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
        List<AvailabilityZone> availabilityZones = availabilityZonesResult.getAvailabilityZones();
        System.out.println("You have access to " + availabilityZones.size() + " availability zones:");
        for (AvailabilityZone zone : availabilityZones) {
            System.out.println(" - " + zone.getZoneName() + " (" + zone.getRegionName() + ")");
        }

        DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
        Set<Instance> instances = new HashSet<Instance>();
        for (Reservation reservation : describeInstancesResult.getReservations()) {
            instances.addAll(reservation.getInstances());
        }

        System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");

        /*
         * The Amazon S3 client allows you to manage and configure buckets
         * and to upload and download data.
         *
         * In this sample, we use the S3 client to list all the buckets in
         * your account, and then iterate over the object metadata for all
         * objects in one bucket to calculate the total object count and
         * space usage for that one bucket. Note that this sample only
         * retrieves the object's metadata and doesn't actually download the
         * object's content.
         *
         * In addition to the low-level Amazon S3 client in the SDK, there
         * is also a high-level TransferManager API that provides
         * asynchronous management of uploads and downloads with an easy to
         * use API:
         *   http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/transfer/TransferManager.html
         */
        List<Bucket> buckets = s3.listBuckets();
        System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s).");

        if (buckets.size() > 0) {
            Bucket bucket = buckets.get(0);

            long totalSize = 0;
            long totalItems = 0;
            /*
             * The S3Objects and S3Versions classes provide convenient APIs
             * for iterating over the contents of your buckets, without
             * having to manually deal with response pagination.
             */
            for (S3ObjectSummary objectSummary : S3Objects.inBucket(s3, bucket.getName())) {
                totalSize += objectSummary.getSize();
                totalItems++;
            }

            System.out.println("The bucket '" + bucket.getName() + "' contains " + 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:SimpleDBWrite.java

License:Open Source License

public static void run(String searchItem) throws Exception {
    /*//www  .  j  a  v a  2  s. c  o  m
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * 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
     */
    AmazonSimpleDB sdb = new AmazonSimpleDBClient(new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    sdb.setRegion(usWest2);

    try {
        // Create a domain
        String myDomain = "WanningStore";
        sdb.createDomain(new CreateDomainRequest(myDomain));

        // List domains
        //            System.out.println("Listing all domains in your account:\n");
        //            for (String domainName : sdb.listDomains().getDomainNames()) {
        //                System.out.println("  " + domainName);
        //            }
        //            System.out.println();

        // Put data into a domain
        System.out.println("Putting data into " + myDomain + " domain.\n");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(myDomain, createData(searchItem)));

        //            // Delete values from an attribute
        //            System.out.println("Deleting Blue attributes in Item_O3.\n");
        //            Attribute deleteValueAttribute = new Attribute("Color", "Blue");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
        //                    .withAttributes(deleteValueAttribute));

        // Delete an attribute and all of its values
        //            System.out.println("Deleting attribute Year in Item_O3.\n");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03")
        //                    .withAttributes(new Attribute().withName("Year")));
        //
        //            // Replace an attribute
        //            System.out.println("Replacing Size of Item_03 with Medium.\n");
        //            List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
        //            replaceableAttributes.add(new ReplaceableAttribute("Size", "Medium", true));
        //            sdb.putAttributes(new PutAttributesRequest(myDomain, "Item_03", replaceableAttributes));
        //
        //            // Delete an item and all of its attributes
        //            System.out.println("Deleting Item_03.\n");
        //            sdb.deleteAttributes(new DeleteAttributesRequest(myDomain, "Item_03"));
        //
        //            // Delete a domain
        //            System.out.println("Deleting " + myDomain + " domain.\n");
        //            sdb.deleteDomain(new DeleteDomainRequest(myDomain));
    } 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:SimpleQueueService.java

License:Open Source License

public static AmazonSQS push(HashMap<String, Integer> data, String Queuename) throws Exception {
    /*/*  w w  w  .java2s .  c o m*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     *
     * 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
     */
    AmazonSQS sqs = new AmazonSQSClient(new ClasspathPropertiesFileCredentialsProvider());
    /*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 {
        // Create a queue

        String myQueueUrl = null;

        System.out.println("Creating/ a new SQS queue called " + Queuename);
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(Queuename);
        /**
            * the AWS API, the call to createQueue, shown in Listing 2, 
            * doesn't necessarily create a new queue every time. If the queue already exists, its handle is returned. In SQS, queues are just URLs; consequently, a queue handle is also just a URL. Note that in the AWS SDK API,
            *  the Queue URL is a String type and not the Java URL type
            * */

        myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();
        QueuePath = myQueueUrl;
        System.out.println();

        // Send a message
        System.out.println("Sending a message to MyQueue.\n");
        sqs.sendMessage(new SendMessageRequest(myQueueUrl, data.toString()));

        return sqs;

    } 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());
    }
    return sqs;
}

From source file:Security.java

License:Open Source License

String createSG(AmazonEC2 ec2) throws IOException {
    try {//w  ww  .  ja v a2s .c o  m
        securitygroup = "VirualIT_Security_Group" + Virtualize.no_of_days;
        CreateSecurityGroupRequest reqsec = new CreateSecurityGroupRequest().withGroupName(securitygroup)
                .withDescription("ssh-tcp-https-http");
        CreateSecurityGroupResult ressec = ec2.createSecurityGroup(reqsec);
        String ipAddr = "0.0.0.0/0";
        ArrayList<String> ipRanges = new ArrayList<String>();
        ipRanges.add(ipAddr);
        ArrayList<IpPermission> ipPermissions = new ArrayList<IpPermission>();
        IpPermission ipPermission_ssh = new IpPermission();
        ipPermission_ssh.setIpProtocol("tcp");
        ipPermission_ssh.setFromPort(new Integer(22));
        ipPermission_ssh.setToPort(new Integer(22));
        IpPermission ipPermission_http = new IpPermission();
        ipPermission_http.setIpProtocol("tcp");
        ipPermission_http.setFromPort(new Integer(80));
        ipPermission_http.setToPort(new Integer(80));
        IpPermission ipPermission_https = new IpPermission();
        ipPermission_https.setIpProtocol("tcp");
        ipPermission_https.setFromPort(new Integer(443));
        ipPermission_https.setToPort(new Integer(443));
        ipPermission_ssh.setIpRanges(ipRanges);
        ipPermission_http.setIpRanges(ipRanges);
        ipPermission_https.setIpRanges(ipRanges);
        ipPermissions.add(ipPermission_http);
        ipPermissions.add(ipPermission_https);
        ipPermissions.add(ipPermission_ssh);
        try {
            // Authorize the ports to the used.
            AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest(
                    securitygroup, ipPermissions);
            ec2.authorizeSecurityGroupIngress(ingressRequest);
            System.out.println("Assigned " + ingressRequest);
        } catch (AmazonServiceException ase) {
            // Ignore because this likely means the zone has already been authorized.
            System.err.println(ase.getMessage());
        }
        DescribeSecurityGroupsRequest x = new DescribeSecurityGroupsRequest().withGroupNames(securitygroup);
        DescribeSecurityGroupsResult secgrp = ec2.describeSecurityGroups(x);
        for (SecurityGroup s : secgrp.getSecurityGroups()) {
            if (s.getGroupName().equals(securitygroup)) {
                System.out.println(s.getIpPermissions());
            }
        }
    } 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());
    }

    return securitygroup;
}

From source file:AmazonDynamoDBSample_PutThrottled.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();//from  ww  w . ja v a 2s .c o  m

    try {
        String tableName = "my-favorite-movies-table";

        // Create a table with a primary hash key named 'name', which holds
        // a string
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
                .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                        new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L));

        // Create table if it does not exist yet
        TableUtils.createTableIfNotExists(dynamoDB, createTableRequest);
        // wait for the table to move into ACTIVE state
        TableUtils.waitUntilActive(dynamoDB, 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);

        Thread[] thrds = new Thread[16];
        for (int i = 0; i < thrds.length; i++) {
            thrds[i] = newItemCreationThread(tableName, i);
            thrds[i].start();
        }
        for (Thread thrd : thrds) {
            thrd.join();
        }

        // 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);

    } 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) {
        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());
    }
}