Book Image

DynamoDB Cookbook

By : Tanmay Deshpande
Book Image

DynamoDB Cookbook

By: Tanmay Deshpande

Overview of this book

Table of Contents (18 chapters)
DynamoDB Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Downloading and setting up DynamoDB Local


A call to any cloud resource may cost money to you, even if you are just doing development and not talking about any hosting in the production cluster. During development, we may need to try many things, and all those trials would cost us. The development best practices demand us to follow a test-driven development. For continuous integration and builds, it's good to run unit tests and integration tests to make sure that the build is intact. If we keep running unit tests and integration tests on the actual DynamoDB, we may end up paying a lot. To cater to this issue, we have something called as DynamoDB Local.

DynamoDB Local is a small client-side database and server that mimics the actual DynamoDB. It enables you to develop and test your code in the local environment, without modifying anything on the actual DynamoDB. It is compatible with the actual DynamoDB API, so there is no need to worry about duplicating your efforts.

Getting ready

DynamoDB Local is a Java Archive (JAR) file, which will run on the Windows, Mac, or Linux machines. To execute these APIs, you should have Java Runtime Engine (JRE) 6.0+ installed on your machine. You can refer to following docs to install JRE on your machine:

For Windows 64-bit machine: http://www.oracle.com/technetwork/java/javase/install-windows-64-142952.html.

For Windows 32-bit machine: http://www.oracle.com/technetwork/java/javase/install-windows-141940.html.

For Mac: http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jre.html.

How to do it…

You can download DynamoDB Local from the following locations:

Now, let's perform the following steps to install DynamoDB Local:

  1. Once done, just unzip the .jar file, and save it in a folder.

  2. Now use Command Prompt, go to the folder where you have unzipped the .jar file, and execute the following command:

    java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar
    

    You will see the jetty server getting started at http://localhost:8000:

  3. Now you can use this as an endpoint for your development. For example, if we want to use it in the Java SDK, we can use this as follows:

    client = new AmazonDynamoDBClient(credentials);
    client.setEndpoint("http://localhost:8000");

    We will see more of its uses in the following chapters.

How it works…

DynamoDB Local is a simple .jar file that runs on your local machine and mimics the actual DynamoDB. You can do your development using DynamoDB, test your code, and simply redirect to the actual DynamoDB whenever it is ready for production deployment. Even though DynamoDB Local mimics most of the DynamoDB features, it does not support some important ones, which are as follows:

  • It does not consider the provisioned throughput settings while making any calls.

  • It does not throttle the read or write activity. The CreateTable, UpdateTable, and DeleteTable operations occur immediately. The table state is always ACTIVE.

  • It does not keep track of the consumed capacity units. So, it always returns null instead of the actual capacity units.

  • Read operations in DynamoDB are eventually consistent, but due to the speed of DynamoDB Local, it appears to be strongly consistent.

There's more…

The DynamoDB Local .jar gives you various other options in addition in order to manage DynamoDB Local smoothly. Here are some more options:

The -help function will list all the options available with DynamoDB Local JAR, as shown in the following command:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar – help

The output is shown in the following command: