Example usage for com.amazonaws AmazonServiceException getErrorMessage

List of usage examples for com.amazonaws AmazonServiceException getErrorMessage

Introduction

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

Prototype

public String getErrorMessage() 

Source Link

Usage

From source file:AmazonKinesisFirehoseToRedshiftSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();//from  www . j av a  2 s  . co m

    try {
        // Create S3 bucket for DeliveryStream to deliver data
        createS3Bucket();

        // Create the DeliveryStream
        createDeliveryStream();

        // Print the list of delivery streams
        printDeliveryStreams();

        // Put records into DeliveryStream
        LOG.info("Putting records in DeliveryStream : " + deliveryStreamName + " via Put Record method.");
        putRecordIntoDeliveryStream();

        // Batch Put records into DeliveryStream
        LOG.info("Putting records in DeliveryStream : " + deliveryStreamName
                + " via Put Record Batch method. Now you can check your S3 bucket " + s3BucketName
                + " for the data delivered by DeliveryStream.");
        putRecordBatchIntoDeliveryStream();

        // Wait for some interval for the firehose to write data to redshift destination
        int waitTimeSecs = s3DestinationIntervalInSeconds == null ? DEFAULT_WAIT_INTERVAL_FOR_DATA_DELIVERY_SECS
                : s3DestinationIntervalInSeconds;
        waitForDataDelivery(waitTimeSecs);

        // Update the DeliveryStream and Put records into updated DeliveryStream, only if the flag is set
        if (enableUpdateDestination) {
            // Update the DeliveryStream
            updateDeliveryStream();

            // Wait for some interval to propagate the updated configuration options before ingesting data
            LOG.info("Waiting for few seconds to propagate the updated configuration options.");
            TimeUnit.SECONDS.sleep(60);

            // Put records into updated DeliveryStream.
            LOG.info("Putting records in updated DeliveryStream : " + deliveryStreamName
                    + " via Put Record method.");
            putRecordIntoDeliveryStream();

            // Batch Put records into updated DeliveryStream.
            LOG.info("Putting records in updated DeliveryStream : " + deliveryStreamName
                    + " via Put Record Batch method.");
            putRecordBatchIntoDeliveryStream();

            // Wait for some interval for the DeliveryStream to write data to redshift destination
            waitForDataDelivery(waitTimeSecs);
        }
    } catch (AmazonServiceException ase) {
        LOG.error("Caught Amazon Service Exception");
        LOG.error("Status Code " + ase.getErrorCode());
        LOG.error("Message: " + ase.getErrorMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error("Caught Amazon Client Exception");
        LOG.error("Exception Message " + ace.getMessage(), ace);
    }
}

From source file:AmazonKinesisFirehoseToS3Sample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    init();// www.ja va 2 s  .  co m

    try {
        // Create S3 bucket for deliveryStream to deliver data
        createS3Bucket();

        // Create the DeliveryStream
        createDeliveryStream();

        // Print the list of delivery streams
        printDeliveryStreams();

        // Put records into deliveryStream
        LOG.info("Putting records in deliveryStream : " + deliveryStreamName + " via Put Record method.");
        putRecordIntoDeliveryStream();

        // Batch Put records into deliveryStream
        LOG.info("Putting records in deliveryStream : " + deliveryStreamName
                + " via Put Record Batch method. Now you can check your S3 bucket " + s3BucketName
                + " for the data delivered by deliveryStream.");
        putRecordBatchIntoDeliveryStream();

        // Wait for some interval for the firehose to write data to the S3 bucket
        int waitTimeSecs = s3DestinationIntervalInSeconds == null ? DEFAULT_WAIT_INTERVAL_FOR_DATA_DELIVERY_SECS
                : s3DestinationIntervalInSeconds;
        waitForDataDelivery(waitTimeSecs);

        // Update the deliveryStream and Put records into updated deliveryStream, only if the flag is set
        if (enableUpdateDestination) {
            // Update the deliveryStream
            updateDeliveryStream();

            // Wait for some interval to propagate the updated configuration options before ingesting data
            LOG.info("Waiting for few seconds to propagate the updated configuration options.");
            TimeUnit.SECONDS.sleep(60);

            // Put records into updated deliveryStream. Records will be delivered to new S3 prefix location
            LOG.info("Putting records in updated deliveryStream : " + deliveryStreamName
                    + " via Put Record method.");
            putRecordIntoDeliveryStream();

            // Batch Put records into updated deliveryStream. Records will be delivered to new S3 prefix location
            LOG.info("Putting records in updated deliveryStream : " + deliveryStreamName
                    + " via Put Record Batch method.");
            putRecordBatchIntoDeliveryStream();

            // Wait for some interval for the deliveryStream to write data to new prefix location in S3 bucket
            waitTimeSecs = updateIntervalInSeconds == null ? waitTimeSecs : updateIntervalInSeconds;
            waitForDataDelivery(waitTimeSecs);
        }
    } catch (AmazonServiceException ase) {
        LOG.error("Caught Amazon Service Exception");
        LOG.error("Status Code " + ase.getErrorCode());
        LOG.error("Message: " + ase.getErrorMessage(), ase);
    } catch (AmazonClientException ace) {
        LOG.error("Caught Amazon Client Exception");
        LOG.error("Exception Message " + ace.getMessage(), ace);
    }
}

From source file:aws.example.dynamodb.CreateTable.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    CreateTable <table>\n\n" + "Where:\n"
            + "    table - the table to create.\n\n" + "Example:\n" + "    CreateTable HelloTable\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);//  w w  w  . j  a  v  a2  s.c  om
    }

    /* Read the name from command args */
    String table_name = args[0];

    System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", table_name);

    CreateTableRequest request = new CreateTableRequest()
            .withAttributeDefinitions(new AttributeDefinition("Name", ScalarAttributeType.S))
            .withKeySchema(new KeySchemaElement("Name", KeyType.HASH))
            .withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10)))
            .withTableName(table_name);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        CreateTableResult result = ddb.createTable(request);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.dynamodb.CreateTableCompositeKey.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    CreateTable <table>\n\n" + "Where:\n"
            + "    table - the table to create.\n\n" + "Example:\n" + "    CreateTable GreetingsTable\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);/*www  .  j  a v a 2 s  . co  m*/
    }

    /* Read the name from command args */
    String table_name = args[0];

    System.out.format("Creating table %s\n with a composite primary key:\n");
    System.out.format("* Language - partition key\n");
    System.out.format("* Greeting - sort key\n");

    CreateTableRequest request = new CreateTableRequest()
            .withAttributeDefinitions(new AttributeDefinition("Language", ScalarAttributeType.S),
                    new AttributeDefinition("Greeting", ScalarAttributeType.S))
            .withKeySchema(new KeySchemaElement("Language", KeyType.HASH),
                    new KeySchemaElement("Greeting", KeyType.RANGE))
            .withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10)))
            .withTableName(table_name);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        CreateTableResult result = ddb.createTable(request);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.dynamodb.DeleteItem.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DeleteItem <table> <name>\n\n" + "Where:\n"
            + "    table - the table to delete the item from.\n"
            + "    name  - the item to delete from the table,\n"
            + "            using the primary key \"Name\"\n\n" + "Example:\n"
            + "    DeleteItem HelloTable World\n\n" + "**Warning** This program will actually delete the item\n"
            + "            that you specify!\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);/*  ww w  .j  a  v a  2s . c o  m*/
    }

    String table_name = args[0];
    String name = args[1];

    System.out.format("Deleting item \"%s\" from %s\n", name, table_name);

    HashMap<String, AttributeValue> key_to_get = new HashMap<String, AttributeValue>();

    key_to_get.put("Name", new AttributeValue(name));

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.deleteItem(table_name, key_to_get);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }

    System.out.println("Done!");
}

From source file:aws.example.dynamodb.DeleteTable.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DeleteTable <table>\n\n" + "Where:\n"
            + "    table - the table to delete.\n\n" + "Example:\n" + "    DeleteTable Greetings\n\n"
            + "**Warning** This program will actually delete the table\n" + "            that you specify!\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);/*from  ww  w  .j a  v  a  2s. c o  m*/
    }

    String table_name = args[0];

    System.out.format("Deleting table %s...\n", table_name);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.deleteTable(table_name);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}

From source file:aws.example.dynamodb.DescribeTable.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DescribeTable <table>\n\n" + "Where:\n"
            + "    table - the table to get information about.\n\n" + "Example:\n"
            + "    DescribeTable HelloTable\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);// ww  w  . j a  v  a 2s  . co m
    }

    String table_name = args[0];
    System.out.format("Getting description for %s\n\n", table_name);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        TableDescription table_info = ddb.describeTable(table_name).getTable();

        if (table_info != null) {
            System.out.format("Table name  : %s\n", table_info.getTableName());
            System.out.format("Table ARN   : %s\n", table_info.getTableArn());
            System.out.format("Status      : %s\n", table_info.getTableStatus());
            System.out.format("Item count  : %d\n", table_info.getItemCount().longValue());
            System.out.format("Size (bytes): %d\n", table_info.getTableSizeBytes().longValue());

            ProvisionedThroughputDescription throughput_info = table_info.getProvisionedThroughput();
            System.out.println("Throughput");
            System.out.format("  Read Capacity : %d\n", throughput_info.getReadCapacityUnits().longValue());
            System.out.format("  Write Capacity: %d\n", throughput_info.getWriteCapacityUnits().longValue());

            List<AttributeDefinition> attributes = table_info.getAttributeDefinitions();
            System.out.println("Attributes");
            for (AttributeDefinition a : attributes) {
                System.out.format("  %s (%s)\n", a.getAttributeName(), a.getAttributeType());
            }
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("\nDone!");
}

From source file:aws.example.dynamodb.GetItem.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    GetItem <table> <name> [projection_expression]\n\n"
            + "Where:\n" + "    table - the table to get an item from.\n" + "    name  - the item to get.\n\n"
            + "You can add an optional projection expression (a quote-delimited,\n"
            + "comma-separated list of attributes to retrieve) to limit the\n"
            + "fields returned from the table.\n\n" + "Example:\n" + "    GetItem HelloTable World\n"
            + "    GetItem SiteColors text \"default, bold\"\n";

    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);// w w  w  . j  a  v  a  2s .c  om
    }

    String table_name = args[0];
    String name = args[1];
    String projection_expression = null;

    // if a projection expression was included, set it.
    if (args.length == 3) {
        projection_expression = args[2];
    }

    System.out.format("Retrieving item \"%s\" from \"%s\"\n", name, table_name);

    HashMap<String, AttributeValue> key_to_get = new HashMap<String, AttributeValue>();

    key_to_get.put("Name", new AttributeValue(name));

    GetItemRequest request = null;
    if (projection_expression != null) {
        request = new GetItemRequest().withKey(key_to_get).withTableName(table_name)
                .withProjectionExpression(projection_expression);
    } else {
        request = new GetItemRequest().withKey(key_to_get).withTableName(table_name);
    }

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        Map<String, AttributeValue> returned_item = ddb.getItem(request).getItem();
        if (returned_item != null) {
            Set<String> keys = returned_item.keySet();
            for (String key : keys) {
                System.out.format("%s: %s\n", key, returned_item.get(key).toString());
            }
        } else {
            System.out.format("No item found with the key %s!\n", name);
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
}

From source file:aws.example.dynamodb.ListTables.java

License:Open Source License

public static void main(String[] args) {
    System.out.println("Your DynamoDB tables:\n");

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    boolean more_tables = true;
    while (more_tables) {
        String last_name = null;//from www. j a  v  a  2s.c o m
        try {
            ListTablesResult table_list = null;
            if (last_name == null) {
                table_list = ddb.listTables();
            } else {
                table_list = ddb.listTables(last_name);
            }

            List<String> table_names = table_list.getTableNames();

            if (table_names.size() > 0) {
                for (String cur_name : table_names) {
                    System.out.format("* %s\n", cur_name);
                }
            } else {
                System.out.println("No tables found!");
                System.exit(0);
            }

            last_name = table_list.getLastEvaluatedTableName();
            if (last_name == null) {
                more_tables = false;
            }
        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
    }
    System.out.println("\nDone!");
}

From source file:aws.example.dynamodb.Query.java

License:Open Source License

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    Query <table> <read> <write>\n\n" + "Where:\n"
            + "    table - the table to put the item in.\n"
            + "    read  - the new read capacity of the table.\n"
            + "    write - the new write capacity of the table.\n\n" + "Example:\n"
            + "    Query HelloTable 16 10\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);//from   w  ww.ja v a 2 s.  c om
    }

    String table_name = args[0];
    Long read_capacity = Long.parseLong(args[1]);
    Long write_capacity = Long.parseLong(args[2]);

    System.out.format("Updating %s with new provisioned throughput values\n", table_name);
    System.out.format("Read capacity : %d\n", read_capacity);
    System.out.format("Write capacity : %d\n", write_capacity);

    ProvisionedThroughput table_throughput = new ProvisionedThroughput(read_capacity, write_capacity);

    final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient();

    try {
        ddb.updateTable(table_name, table_throughput);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}