Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

Java and DAX

To run the Java sample on your Amazon EC2 instance, follow this procedure:

  1. Install the Java Development Kit (JDK):

    sudo yum install -y java-devel
  2. Download the AWS SDK for Java (.zip file), and then extract it:

    wget unzip
  3. Download the latest version of the DAX Java client (.jar file):

  4. Set your CLASSPATH variable:

    export SDKVERSION=sdkVersion export CLASSPATH=.:./DaxJavaClient-latest.jar:aws-java-sdk-$SDKVERSION/lib/aws-java-sdk-$SDKVERSION.jar:aws-java-sdk-$SDKVERSION/third-party/lib/*

    Replace sdkVersion with the actual version number of the AWS SDK for Java. For example: 1.11.112

  5. Download the sample program source code (.zip file):


    When the download is complete, extract the source files:

  6. Compile the code as follows:

    javac TryDax*.java
  7. Run the program:

    java TryDax

    You should see output similar to the following:

    Creating a DynamoDB client Attempting to create table; please wait... Successfully created table. Table status: ACTIVE Writing data to the table... Writing 10 items for partition key: 1 Writing 10 items for partition key: 2 Writing 10 items for partition key: 3 Writing 10 items for partition key: 4 Writing 10 items for partition key: 5 Writing 10 items for partition key: 6 Writing 10 items for partition key: 7 Writing 10 items for partition key: 8 Writing 10 items for partition key: 9 Writing 10 items for partition key: 10 Running GetItem, Scan, and Query tests... First iteration of each test will result in cache misses Next iterations are cache hits GetItem test - partition key 1 and sort keys 1-10 Total time: 136.681 ms - Avg time: 13.668 ms Total time: 122.632 ms - Avg time: 12.263 ms Total time: 167.762 ms - Avg time: 16.776 ms Total time: 108.130 ms - Avg time: 10.813 ms Total time: 137.890 ms - Avg time: 13.789 ms Query test - partition key 5 and sort keys between 2 and 9 Total time: 13.560 ms - Avg time: 2.712 ms Total time: 11.339 ms - Avg time: 2.268 ms Total time: 7.809 ms - Avg time: 1.562 ms Total time: 10.736 ms - Avg time: 2.147 ms Total time: 12.122 ms - Avg time: 2.424 ms Scan test - all items in the table Total time: 58.952 ms - Avg time: 11.790 ms Total time: 25.507 ms - Avg time: 5.101 ms Total time: 37.660 ms - Avg time: 7.532 ms Total time: 26.781 ms - Avg time: 5.356 ms Total time: 46.076 ms - Avg time: 9.215 ms Attempting to delete table; please wait... Successfully deleted table.

    Take note of the timing information—the number of milliseconds required for the GetItem, Query and Scan tests.

  8. In the previous step, you ran the program against the DynamoDB endpoint. You will now run the program again, but this time the GetItem, Query and Scan operations will be processed by your DAX cluster.

    To determine the endpoint for your DAX cluster, choose one of the following:

    • Using the DynamoDB console—choose your DAX cluster. The cluster endpoint is shown in the console. For example:
    • Using the AWS CLI—type the following command:

      aws dax describe-clusters --query "Clusters[*].ClusterDiscoveryEndpoint"

      The cluster endpoint port and address are shown in the output. For example:

      { "Port": 8111, "Address":"" }

    Now run the program again—but this time, specify the cluster endpoint as a command line parameter:

    java TryDax

    Look at the rest of the output, and take note of the timing information. The elapsed times for GetItem, Query and Scan should be significantly lower with DAX than with DynamoDB.

For more information about this program, see the following sections: