Create local DynamoDB Service

Need to create a local DynamoDB service within Ubuntu on Windows Subsystem for Linux 2

Setup the latest Java Runtime Environment for your distribution

  1. java -version
Command 'java' not found, but can be installed with:
sudo apt install openjdk-11-jre-headless  # version 11.0.20.1+1-0ubuntu1~22.04, or
sudo apt install default-jre              # version 2:1.11-72build2
sudo apt install openjdk-17-jre-headless  # version 17.0.8.1+1~us1-0ubuntu1~22.04
sudo apt install openjdk-18-jre-headless  # version 18.0.2+9-2~22.04
sudo apt install openjdk-19-jre-headless  # version 19.0.2+7-0ubuntu3~22.04
sudo apt install openjdk-8-jre-headless   # version 8u382-ga-1~22.04.1
  1. Install the latest JRE sudo apt install openjdk-19-jre-headless

Download the DynamoDB jar

  • Choose the local option on this link

Extract and copy the contents to the following folder

sudo tar -xvzf dynamodb_local_latest.tar.gz -C /usr/lib/dynamodb

Create a Systemd service file for DynamoDb

  • Go to the directory /lib/systemd/system
  • Create a new file dynamodb.service
  • Paste these contents into it
[Unit]
Description=Dynamo DB Local Service
[Service]
User=root
# The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/usr/lib/dynamodb
#path to executable.
#executable is a bash script which calls jar file
ExecStart=/usr/lib/dynamodb/dynamodb
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
  • Create a dynamo run file in the /usr/lib/dynamodb folder to match the above config
  • Go to folder /usr/lib/dynamodb
  • Create a new run file like this sudo nano dynamodb
  • Paste this into file
#!/bin/sh
sudo java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
  • Make it runnable sudo chmod 755 dynamodb
  • Go to the directory /etc/systemd/system
  • Create a symbolic link like so ln -s /lib/systemd/system/dynamodb.service dynamo.service (optional step)
  • Test the service works sudo systemctl start dynamodb
  • Enable the service to (includes autostart defined in systemd file above) sudo systemctl enable dynamodb