Skip to content

Local Dev ‐ Dynamo

Manasa Venkatakrishnan edited this page Oct 2, 2023 · 3 revisions

This setup guide is for running local dynamo from zip files.

Setting up java

Try running, java -version on your commandline. If you have java runtime environment set up, you should see something like this below:

$ java -version
java version "1.8.0_361"
Java(TM) SE Runtime Environment (build 1.8.0_361-b09)

If you don't, please go through the jre setup from here. Once the setup is complete and the path to java is in your PATH environment variable, try running the above command. You should now be able to get the java version you are running.

Downloading files

You can download the files from here and extract them.

Starting up

To start the local DynamoDB, navigate to the directory where you extracted DynamoDBLocal.jar and enter the following command:

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

Ensure that the AWS_ACCESS_KEY_ID and the AWS_SECRET_ACCESS_KEY environment variables are set up with fake values before requesting the local dynamo.

Alternative setup with Docker

You can alternatively set up dynamo locally using docker with the guide provided here.

Requirements for the script

  • It requires a local dynamo to be running. Please take a look at the section above for setting up local dynamo.
  • aws CLI to be available. Please refer here to find relevant documentation.
  • jq package to be available. If jq is not already available, it will try to install it using brew or macPorts.
  • env variable AWS_PROFILE set up with a profile name with access to the staging tables or other configured source tables.

Optional Environment Variables for customizations

The following environment variables can be set with values to override default values.

  • REMOTE_DYNAMO_PREFIX can be configured to the prefix of the remote table to be used as the source when creating new tables. This defaults to staging.
  • LOCAL_DYNAMO_PREFIX can be configured to the prefix of the local dynamo table to be created. This defaults to local.
  • LOCAL_DYNAMO_PORT can be configured to the port where the local dynamo is listening. This defaults to 8000.

How to run the script

The script takes the names of tables to be created as arguments.

To access the remote table, you may need to set your AWS_PROFILE environment variable. Before running any of the below commands, make sure you run:

$ export AWS_PROFILE=sci-imaging

The script can be run from the command line as follows, from the folder where the script exists.

$ ./local-dynamo-setup.sh "install-activity" 

This will create the table local-install-activity if it doesn't already exist in the local dynamo. This will also provide an option to backfill the local table with all the data present in the remote table.

Multiple table names can also be passed in a single invocation as follows:

$ ./local-dynamo-setup.sh plugin-metadata category

The following command should create all the tables needed for the backend application:

$ ./local-dynamo-setup.sh category plugin plugin-metadata plugin-blocked install-activity github-activity 

Pointing applications to local dynamo

When running locally, set up the LOCAL_DYNAMO_HOST environment variable to http://localhost:8000 or where ever your local dynamo is running, and STACK_NAME to local or any other value configured using LOCAL_DYNAMO_PREFIX Example:

$ export LOCAL_DYNAMO_HOST="http://localhost:8000"
$ export STACK_NAME="local"

In the pynamo models, set up the host attribute of the metaclass to get the value assigned to LOCAL_DYNAMO_HOST environment variable. As done here.

Using the AWS CLI

For more information on using the AWS CLI, please click here.