How to Download a Local Copy of DynamoDB from AWS

By John Paul Mueller

In contrast to many of the other AWS services, you can actually get a local copy of DynamoDB that you can work with offline. Using DynamoDB offline, on your local machine, means that you can try various tasks without incurring costs or worrying about potential connectivity issues.

In addition, you can use DynamoDB in a test environment, in which you use a copy of your data to mimic real-world situations. Here, you discover how to obtain and install a local copy and then use your copy with Python to perform a test.

Performing the installation

To start using a local copy of DynamoDB, you need Java installed on your system because Amazon supplies DynamoDB as a .jar file. You can obtain a user-level version of Java. However, if you plan to perform any customizations or feel you might need debugging support, then you need a developer version of Java (the Java Development Kit or JDK). Make sure to get the latest version of Java to ensure that DynamoDB works as expected.

The next step is to download a copy of DynamoDB and extract the files in the archive. Note that you can get versions of DynamoDB that work with Maven and Eclipse. These instructions assume that you use the pure Java version and that you’ve extracted the downloaded archive to a folder named DynamoDB on your hard drive. You may need to bury the archive a level or two deep, but make sure that the path doesn’t contain spaces. The main file you deal with is DynamoDBLocal.jar.

Starting DynamoDB locally

Open a command prompt or terminal window and ensure that you’re in the location where you extracted the DynamoDB archive (using the CD command). Type java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar –sharedDb and press Enter to start DynamoDB. Depending on your operating system, you see some startup messages.

DynamoDB AWS
DynamoDB displays some startup messages after you execute the command.

When working with Windows, you should also see the message below (other platforms may show other messages). This firewall message tells you that port 8000 isn’t currently open. To make DyanmoDB work properly, you must allow access. If you want to change the port, use the -port command-line switch with a different port number. The page that contains the DynamoDB links also has a list of other command-line switches near the bottom, or you can use the -help command-line switch to see a listing for these command line switches locally.

firewall access AWS
Allow access to port 8000 through your firewall.

Overcoming the Windows OSError issue

When working with Windows, you may encounter a problem that involves seeing an OSError message output for some Python calls, even if your code is correct. The problem is with the tz.py file found in the \Users\<UserName>\Anaconda3\Lib\site-packages\dateutil\tz folder of your Anaconda setup (the same file exists for every Python setup, but in different folders). To fix this problem, you must change the code for the _naive_is_dst() function so that it looks like this:

def _naive_is_dst(self, dt):

# Original Code

timestamp = _datetime_to_timestamp(dt)

#return time.localtime(timestamp +

time.timezone).tm_isdst

 

# Bug Fix Code

if timestamp+time.timezone &lt; 0:

current_time = timestamp + time.timezone +

31536000

 

else:

current_time = timestamp + time.timezone

 

return time.localtime(current_time).tm_isdst

Fortunately, you don’t have to make the change yourself. You can find the updated tz.py file in the downloadable source, as explained in the Introduction. Just copy it to the appropriate folder on your system.

At this point, you can begin using your local copy of DynamoDB to perform tasks.