Skip to content

Import json data to DynamoDB script

rmccar edited this page Mar 25, 2019 · 3 revisions

import-json-to-dynamo.js

This is a script to run be against any questionnaire json files in a specified folder and they will then be added to DynamoDB. The script works by looping through the directory passed to it with the DATA_DIR variable, and running the createQuestionnaire function for each one. This function is the same one run when you create a questionnaire through the Author web interface and will create a new questionnaire in Dynamo for each json file in the same way.

Location

The script is held in the eq-author-app/eq-author-api/scripts/ folder.

How To Use

The script has a number of environment variables that need to be set in order for it to run.

Environment Variables

Variable Description
AWS_REGION The region your DynamoDB is in on AWS
AWS_ACCESS_KEY_ID Your access key ID for AWS, if running locally set this to 'dummy'
AWS_SECRET_ACCESS_KEY Your secret access key ID for AWS, if running locally set this to 'dummy'
DYNAMO_QUESTIONNAIRE_TABLE_NAME The questionnaire versions table name - the table that you want the questionnaire added to
DYNAMO_QUESTIONNAIRE_VERSION_TABLE_NAME The questionnaire list table name - the table that lists the current version of each questionnaire
DYNAMO_ENDPOINT_OVERRIDE Allows you to set the AWS endpoint, set this to 'http://localhost:8050' if running locally
DATA_DIR Folder path to the folder that holds the json files to be imported

Example Run Command

These variables can be set in the command you run it with when running from the command line. This is an example command line that has been used to run the script locally:

AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=dummy AWS_SECRET_ACCESS_KEY=dummy DYNAMO_QUESTIONNAIRE_TABLE_NAME=dev-author-questionnaires DYNAMO_QUESTIONNAIRE_VERSION_TABLE_NAME=dev-author-questionnaire-versions DYNAMO_ENDPOINT_OVERRIDE=http://localhost:8050 DATA_DIR=../data node import-json-to-dynamo.js

Clone this wiki locally