Deploy a Local DynamoDB for Testing
I didn't realize until recently that you can run DynamoDB on a local machine on either Windows, Mac, or Linux. This obviously can be hugely benefitial for learning and dabbling in DynamoDB, without racking up a large AWS bill. Let's see if we can get this running in a Vagrant VM, with a bit of automation so that we can spin up and spin down new instances quickly.
Checkout my article on using Vagrant if you need a refresher.
First, let's make a few Vagrantfile edits. We're going to forward port 8000 and also run a few steps to install DynamoDB. Based on the documentation, all you have to do is run the jar file that you download and extract from AWS. To do this, we'll first need to install java. It seems to work okay with OpenJDK, which is immediately available through dnf/yum, so we'll use that.
I always make it a habit to run a dnf/yum update as well when deploying a new system, so let's add that to the list of commands too. Finally, we'll extract the tar.gz file and run it. Assuming all goes well, we'll be ready to run against our new DynamoDB machine.
Also I attempted to get it working with Firewalld, but there appears to be some other ports that I'm not aware of, so in the interest of keeping all my hair, let's turn it off.
sudo dnf -y update
sudo systemctl stop firewalld.service
sudo dnf -y install java
sudo mkdir /var/dynamo
rm -rf /var/dynamo/*
tar -xzf dynamodb_local_latest.tar.gz --directory /var/dynamo
/usr/bin/java -Djava.library.path=/var/dynamodb/DynamoDBLocal_lib -jar /var/dynamodb/DynamoDBLocal.jar -sharedDb
Try it out
Using an AWS cli installation anywhere that can access your newly built DynamoDB, run the following command:
aws dynamodb list-tables --endpoint-url http://localhost:8000
you can also isntall the AWS CLI directly on this VM with
pip3 install awscli --upgrade --user
When you try to run it, you'll need to configure AWS. The beauty of running dynamodb locally is you don't need to worry about the Access and Secret keys. Just put anything. For the region, I just put us-east-1. You can modify some of the settings to use different data based on region, but we don't do that here.
Run it as a Service
Create a file called dynamodb.service in the /usr/lib/systemd/system This file will treat the jar file as a service, so it can be started automatically and managed via systemd, rather than an active session running the jar file.
ExecStart=/usr/bin/java -Djava.library.path=/var/dynamo/DynamoDBLocal_lib -jar /var/dynamo/DynamoDBLocal.jar -sharedDb
I don't see any reason you couldn't run DynamoDB on a shared VM that multiple devs could point to (not sure it violates a license or something), so for testing, this is definitely a safe and easy alternative.
Alternative to using Vagrant, you can always just run a docker image, available here