Example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient deleteItem

List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient deleteItem

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient deleteItem.

Prototype

@Override
    public DeleteItemResult deleteItem(String tableName, java.util.Map<String, AttributeValue> key) 

Source Link

Usage

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);//from w w  w  .j  a v  a  2s .  c om
    }

    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!");
}