From 4351967bc255eb610e15481a9a1d385e735216dd Mon Sep 17 00:00:00 2001 From: "vikas.peri" Date: Mon, 11 Sep 2023 07:48:26 +0800 Subject: [PATCH 1/4] Upgrade Code to AWS SDK v3 --- lib/actions/purgeTable.js | 27 ++--- lib/backend.js | 202 +++++++++++++++----------------------- lib/util.js | 16 +-- package.json | 3 +- views/scan.ejs | 2 +- 5 files changed, 107 insertions(+), 143 deletions(-) diff --git a/lib/actions/purgeTable.js b/lib/actions/purgeTable.js index 977766f..3a050f9 100644 --- a/lib/actions/purgeTable.js +++ b/lib/actions/purgeTable.js @@ -1,3 +1,4 @@ +const { DescribeTableCommand } = require('@aws-sdk/client-dynamodb') const { doSearch } = require('../util') const findPrimaryKeys = context => { @@ -5,18 +6,20 @@ const findPrimaryKeys = context => { TableName: context.tableName } - return context.dynamodb.describeTable(params).promise() - .then(tableDescription => { - const tableSchema = tableDescription.Table.KeySchema + const DescribeTablePromise = context.dynamodbClient + .send(new DescribeTableCommand(params)) - context.primaryKeys = ['HASH', 'RANGE'] - .map(keyType => tableSchema.find(element => element.KeyType === keyType)) - .filter(attribute => attribute) - .map(attribute => attribute.AttributeName) + return DescribeTablePromise.then(tableDescription => { + const tableSchema = tableDescription.Table.KeySchema + context.primaryKeys = ['HASH', 'RANGE'] + .map(keyType => tableSchema.find(element => element.KeyType === keyType)) + .filter(attribute => attribute) + .map(attribute => attribute.AttributeName) - return context - }) + + return context + }) } const findAllElements = context => { @@ -31,7 +34,7 @@ const findAllElements = context => { ProjectionExpression: Object.keys(ExpressionAttributeNames).join(', '), } - return doSearch(context.dynamodb, context.tableName, scanParams) + return doSearch(context.dynamodbClient, context.tableName, scanParams) .then(items => { context.items = items return context @@ -85,10 +88,10 @@ const deleteAllElements = context => { * @param dynamodb the AWS dynamodb service that holds the connection * @returns {Promise} concatenation of all delete request promises */ -const purgeTable = (tableName, dynamodb) => { +const purgeTable = (tableName, dynamodbClient) => { const context = { tableName, - dynamodb + dynamodbClient } return findPrimaryKeys(context) diff --git a/lib/backend.js b/lib/backend.js index a5a4f64..a78323a 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -1,7 +1,5 @@ const express = require('express') const path = require('path') -const fs = require('fs') -const os = require('os') const errorhandler = require('errorhandler') const { extractKey, extractKeysForItems, parseKey, doSearch } = require('./util') const { purgeTable } = require('./actions/purgeTable') @@ -11,6 +9,11 @@ const pickBy = require('lodash.pickby') const clc = require('cli-color') const cookieParser = require('cookie-parser') const DEFAULT_THEME = process.env.DEFAULT_THEME || 'light' +const { DynamoDBClient, ListTablesCommand } = require('@aws-sdk/client-dynamodb') +const { CreateTableCommand, DescribeTableCommand } = require('@aws-sdk/client-dynamodb') +const { DeleteTableCommand, ScanCommand } = require('@aws-sdk/client-dynamodb') +const { DynamoDBDocumentClient, GetCommand } = require('@aws-sdk/lib-dynamodb') +const { PutCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb') function loadDynamoEndpoint(env, dynamoConfig) { if (typeof env.DYNAMO_ENDPOINT === 'string') { @@ -43,43 +46,20 @@ function loadDynamoEndpoint(env, dynamoConfig) { * @param AWS - the AWS SDK object * @returns {{endpoint: string, sslEnabled: boolean, region: string, accessKeyId: string}} */ -function loadDynamoConfig(env, AWS) { +function loadDynamoConfig(env) { const dynamoConfig = { endpoint: 'http://localhost:8000', sslEnabled: false, - region: 'us-east-1', - accessKeyId: 'key', - secretAccessKey: env.AWS_SECRET_ACCESS_KEY || 'secret' + region: 'us-east-1' } loadDynamoEndpoint(env, dynamoConfig) - - if (AWS.config) { - if (AWS.config.region !== undefined) { - dynamoConfig.region = AWS.config.region - } - - if (AWS.config.credentials) { - if (AWS.config.credentials.accessKeyId !== undefined) { - dynamoConfig.accessKeyId = AWS.config.credentials.accessKeyId - } - } - } - - if (env.AWS_REGION) { - dynamoConfig.region = env.AWS_REGION - } - - if (env.AWS_ACCESS_KEY_ID) { - dynamoConfig.accessKeyId = env.AWS_ACCESS_KEY_ID - } - return dynamoConfig } -const createAwsConfig = (AWS) => { +const createAwsConfig = () => { const env = process.env - const dynamoConfig = loadDynamoConfig(env, AWS) + const dynamoConfig = loadDynamoConfig(env) console.log(clc.blackBright(` database endpoint: \t${dynamoConfig.endpoint}`)) console.log(clc.blackBright(` region: \t\t${dynamoConfig.region}`)) @@ -88,50 +68,30 @@ const createAwsConfig = (AWS) => { return dynamoConfig } -function getHomeDir() { - const env = process.env - const home = env.HOME || env.USERPROFILE - || (env.HOMEPATH ? ((env.HOMEDRIVE || 'C:/') + env.HOMEPATH) : null) - - if (home) { - return home - } - - if (typeof os.homedir === 'function') { - return os.homedir() - } - - return null -} -exports.createServer = (dynamodb, docClient, expressInstance = express()) => { +exports.createServer = (dynamodbClient, docClient, expressInstance = express()) => { const app = expressInstance app.set('json spaces', 2) app.set('view engine', 'ejs') app.set('views', path.resolve(__dirname, '..', 'views')) - if (!dynamodb || !docClient) { - const homeDir = getHomeDir() - - if (homeDir && fs.existsSync(path.join(homeDir, '.aws', 'credentials')) && - fs.existsSync(path.join(homeDir, '.aws', 'config'))) { - process.env.AWS_SDK_LOAD_CONFIG = 1 - } - - const AWS = require('aws-sdk') - - if (!dynamodb) { - dynamodb = new AWS.DynamoDB(createAwsConfig(AWS)) + if (!dynamodbClient || !docClient) { + if (!dynamodbClient) { + dynamodbClient = new DynamoDBClient(createAwsConfig()) } - docClient = docClient || new AWS.DynamoDB.DocumentClient({ service: dynamodb }) + docClient = docClient || DynamoDBDocumentClient.from(dynamodbClient) } - - const listTables = (...args) => dynamodb.listTables(...args).promise() - const describeTable = (...args) => dynamodb.describeTable(...args).promise() - const getItem = (...args) => docClient.get(...args).promise() - const putItem = (...args) => docClient.put(...args).promise() - const deleteItem = (...args) => docClient.delete(...args).promise() + const listTables = (...args) => + dynamodbClient.send(new ListTablesCommand(...args)) + const describeTable = (...args) => + dynamodbClient.send(new DescribeTableCommand(...args)) + const getItem = (...args) => + docClient.send(new GetCommand(...args)) + const putItem = (...args) => + docClient.send(new PutCommand(...args)) + const deleteItem = (...args) => + docClient.send(new DeleteCommand(...args)) app.use(errorhandler()) app.use('/assets', express.static(path.join(__dirname, '..', 'public'))) @@ -218,8 +178,8 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { KeyType: 'HASH' } ] - if (isAttributeNotAlreadyCreated(attributeDefinitions, - secondaryIndex.HashAttributeName)) { + if ( + isAttributeNotAlreadyCreated(attributeDefinitions, secondaryIndex.HashAttributeName)) { attributeDefinitions.push({ AttributeName: secondaryIndex.HashAttributeName, AttributeType: secondaryIndex.HashAttributeType @@ -250,8 +210,8 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { if (secondaryIndex.IndexType === 'global') { index.ProvisionedThroughput = { - ReadCapacityUnits: req.body.ReadCapacityUnits, - WriteCapacityUnits: req.body.WriteCapacityUnits + ReadCapacityUnits: Number(req.body.ReadCapacityUnits), + WriteCapacityUnits: Number(req.body.WriteCapacityUnits) } globalSecondaryIndexes.push(index) } else { @@ -266,19 +226,18 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { if (globalSecondaryIndexes === undefined || globalSecondaryIndexes.length === 0) { globalSecondaryIndexes = undefined } - return dynamodb - .createTable({ - TableName: req.body.TableName, - ProvisionedThroughput: { - ReadCapacityUnits: req.body.ReadCapacityUnits, - WriteCapacityUnits: req.body.WriteCapacityUnits - }, - GlobalSecondaryIndexes: globalSecondaryIndexes, - LocalSecondaryIndexes: localSecondaryIndexes, - KeySchema: keySchema, - AttributeDefinitions: attributeDefinitions - }) - .promise() + const CreateTablePromise = dynamodbClient.send(new CreateTableCommand({ + TableName: req.body.TableName, + ProvisionedThroughput: { + ReadCapacityUnits: Number(req.body.ReadCapacityUnits), + WriteCapacityUnits: Number(req.body.WriteCapacityUnits) + }, + GlobalSecondaryIndexes: globalSecondaryIndexes, + LocalSecondaryIndexes: localSecondaryIndexes, + KeySchema: keySchema, + AttributeDefinitions: attributeDefinitions + })) + return CreateTablePromise .then(() => { res.status(204).end() }).catch(error => { @@ -292,9 +251,8 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { if (tablesList.length === 0) { return res.send('There are no tables to delete') } - await Promise.all(tablesList.map(table => dynamodb - .deleteTable({ TableName: table.TableName }) - .promise() + await Promise.all(tablesList.map(table => + dynamodbClient.send(new DeleteTableCommand({ TableName: table.TableName })) )) return res.send('Tables deleted') })) @@ -304,22 +262,22 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { if (tablesList.length === 0) { return res.send('There are no tables to purge') } - await Promise.all(tablesList.map(table => purgeTable(table.TableName, dynamodb))) + await Promise.all(tablesList.map(table => purgeTable(table.TableName, dynamodbClient))) return res.send('Tables purged') })) app.delete('/tables/:TableName', asyncMiddleware((req, res) => { const TableName = req.params.TableName - return dynamodb - .deleteTable({ TableName }) - .promise() + + const deleteTablePromise = dynamodbClient.send(new DeleteTableCommand({ TableName })) + return deleteTablePromise .then(() => { res.status(204).end() }) })) app.delete('/tables/:TableName/all', asyncMiddleware((req, res) => { - return purgeTable(req.params.TableName, dynamodb) + return purgeTable(req.params.TableName, dynamodbClient) .then(() => { res.status(200).end() }) @@ -330,12 +288,12 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { if (req.query.hash) { if (req.query.range) { return res.redirect( - `/tables/${encodeURIComponent(TableName)}/items/${ - encodeURIComponent(req.query.hash)},${encodeURIComponent(req.query.range)}` + `/tables/${encodeURIComponent(TableName)}/items/${encodeURIComponent(req.query.hash)}, + ${encodeURIComponent(req.query.range)}` ) } else { - return res.redirect(`/tables/${ - encodeURIComponent(TableName)}/items/${encodeURIComponent(req.query.hash)}`) + return res.redirect( + `/tables/${encodeURIComponent(TableName)}/items/${encodeURIComponent(req.query.hash)}`) } } @@ -371,36 +329,36 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { }) })) - const getPage = (docClient, keySchema, TableName, scanParams, pageSize, - startKey, operationType) => { - const pageItems = [] + const getPage = + (docClient, keySchema, TableName, scanParams, pageSize, startKey, operationType) => { + const pageItems = [] - function onNewItems(items, lastStartKey) { - for (let i = 0; i < items.length && pageItems.length < pageSize + 1; i++) { - pageItems.push(items[i]) - } + function onNewItems(items, lastStartKey) { + for (let i = 0; i < items.length && pageItems.length < pageSize + 1; i++) { + pageItems.push(items[i]) + } - // If there is more items to query (!lastStartKey) then don't stop until - // we are over pageSize count. Stopping at exactly pageSize count would - // not extract key of last item later and make pagination not work. - return pageItems.length > pageSize || !lastStartKey - } + // If there is more items to query (!lastStartKey) then don't stop until + // we are over pageSize count. Stopping at exactly pageSize count would + // not extract key of last item later and make pagination not work. + return pageItems.length > pageSize || !lastStartKey + } - return doSearch(docClient, TableName, scanParams, 10, startKey, onNewItems, operationType) - .then(items => { - let nextKey = null + return doSearch(docClient, TableName, scanParams, 10, startKey, onNewItems, operationType) + .then(items => { + let nextKey = null - if (items.length > pageSize) { - items = items.slice(0, pageSize) - nextKey = extractKey(items[pageSize - 1], keySchema) - } + if (items.length > pageSize) { + items = items.slice(0, pageSize) + nextKey = extractKey(items[pageSize - 1], keySchema) + } - return { - pageItems: items, - nextKey, - } - }) - } + return { + pageItems: items, + nextKey, + } + }) + } app.get('/tables/:TableName', asyncMiddleware((req, res) => { const TableName = req.params.TableName @@ -435,7 +393,6 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { const TableName = req.params.TableName req.query = pickBy(req.query) const filters = req.query.filters ? JSON.parse(req.query.filters) : {} - return describeTable({ TableName }) .then(description => { const ExclusiveStartKey = req.query.startKey @@ -523,8 +480,9 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { const pageSize = req.query.pageSize || 25 - return getPage(docClient, description.Table.KeySchema, TableName, - params, pageSize, startKey, req.query.operationType) + return getPage( + docClient, description.Table.KeySchema, TableName, + params, pageSize, startKey, req.query.operationType) .then(results => { const { pageItems, nextKey } = results @@ -568,7 +526,7 @@ exports.createServer = (dynamodb, docClient, expressInstance = express()) => { const TableName = req.params.TableName return Promise.all([ describeTable({ TableName }), - docClient.scan({ TableName }).promise() + () => docClient.send(new ScanCommand({ TableName })) ]) .then(([description, items]) => { const data = Object.assign({}, description, items) diff --git a/lib/util.js b/lib/util.js index 4b5ec99..e6f0201 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,4 +1,6 @@ -exports.extractKey = function(item, KeySchema) { +const { ScanCommand, QueryCommand } = require('@aws-sdk/client-dynamodb') + +exports.extractKey = function (item, KeySchema) { return KeySchema.reduce((prev, current) => { return Object.assign({}, prev, { [current.AttributeName]: item[current.AttributeName] @@ -6,7 +8,7 @@ exports.extractKey = function(item, KeySchema) { }, {}) } -exports.parseKey = function(keys, table) { +exports.parseKey = function (keys, table) { const splitKeys = keys.split(',') return table.KeySchema.reduce((prev, current, index) => { @@ -20,7 +22,7 @@ exports.parseKey = function(keys, table) { }, {}) } -exports.extractKeysForItems = function(Items) { +exports.extractKeysForItems = function (Items) { const keys = new Set() for (const item of Items) { for (const key of Object.keys(item)) { @@ -48,8 +50,8 @@ exports.doSearch = doSearch * @param {string} readOperation The read operation * @return {Promise} Promise with items or rejected promise with error. */ -function doSearch(docClient, tableName, scanParams, limit, startKey, progress, - readOperation = 'scan') { +function doSearch(docClient, tableName, scanParams, limit, + startKey, progress, readOperation = 'scan') { limit = limit !== undefined ? limit : null startKey = startKey !== undefined ? startKey : null let params = { @@ -69,8 +71,8 @@ function doSearch(docClient, tableName, scanParams, limit, startKey, progress, } const readMethod = { - scan: (...args) => docClient.scan(...args).promise(), - query: (...args) => docClient.query(...args).promise(), + scan: (...args) => docClient.send(new ScanCommand(...args)), + query: (...args) => docClient.send(new QueryCommand(...args)) }[readOperation] let items = [] diff --git a/package.json b/package.json index a8e553c..22c9c1a 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,9 @@ }, "homepage": "https://github.com/aaronshaf/dynamodb-viewer#readme", "dependencies": { + "@aws-sdk/client-dynamodb": "^3.405.0", + "@aws-sdk/lib-dynamodb": "3.405.0", "argparse": "^2.0.1", - "aws-sdk": "^2.1225.0", "body-parser": "^1.20.0", "cli-color": "^2.0.3", "cookie-parser": "^1.4.6", diff --git a/views/scan.ejs b/views/scan.ejs index 87ef7b6..efd6606 100644 --- a/views/scan.ejs +++ b/views/scan.ejs @@ -405,7 +405,7 @@ if (data.Items.length) { $('#items-container').append(data.Items.map(item => { - const viewUrl = '/tables/<%= Table.TableName %>/items/' + encodeURIComponent(Object.values(item.__key).join(',')) + const viewUrl = '/tables/<%= Table.TableName %>/items/' + encodeURIComponent(Object.values(Object.values(item.__key)[0]).join(',')) const rowEl = $('View') for (const column of data.uniqueKeys) { From d12e17cd9ad12a5d780aa40591b611cc48775afe Mon Sep 17 00:00:00 2001 From: Vikas Peri Date: Wed, 22 Nov 2023 15:56:47 +0800 Subject: [PATCH 2/4] Fix the credentials issue --- bin/dynamodb-admin.js | 8 +++++++- lib/backend.js | 25 ++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/dynamodb-admin.js b/bin/dynamodb-admin.js index 25bb98d..7356bc9 100755 --- a/bin/dynamodb-admin.js +++ b/bin/dynamodb-admin.js @@ -38,9 +38,15 @@ parser.add_argument('-p', '--port', { help: 'Port to run on (default: 8001)', }) +parser.add_argument('-D', '--dummy_creds', { + action:'store_true', + required: false, + help: 'Use dummy AWS credentials', +}) + const args = parser.parse_args() -const app = createServer() +const app = createServer(undefined,undefined, args.dummy_creds) const host = process.env.HOST || args.host const port = process.env.PORT || args.port const server = app.listen(port, host) diff --git a/lib/backend.js b/lib/backend.js index a78323a..e96bb21 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -46,30 +46,33 @@ function loadDynamoEndpoint(env, dynamoConfig) { * @param AWS - the AWS SDK object * @returns {{endpoint: string, sslEnabled: boolean, region: string, accessKeyId: string}} */ -function loadDynamoConfig(env) { - const dynamoConfig = { +function loadDynamoConfig(env, isDummy) { + let dynamoConfig = { endpoint: 'http://localhost:8000', - sslEnabled: false, - region: 'us-east-1' + sslEnabled: false } + const dummy_creds = isDummy ? {credentials: { + accessKeyId: 'key', + secretAccessKey: 'secret', + region: 'us-east-1', + }}: {} + dynamoConfig = {...dynamoConfig, ...dummy_creds} + loadDynamoEndpoint(env, dynamoConfig) return dynamoConfig } -const createAwsConfig = () => { +const createAwsConfig = (isDummy) => { const env = process.env - const dynamoConfig = loadDynamoConfig(env) + const dynamoConfig = loadDynamoConfig(env, isDummy) console.log(clc.blackBright(` database endpoint: \t${dynamoConfig.endpoint}`)) - console.log(clc.blackBright(` region: \t\t${dynamoConfig.region}`)) - console.log(clc.blackBright(` accessKey: \t\t${dynamoConfig.accessKeyId}\n`)) - return dynamoConfig } -exports.createServer = (dynamodbClient, docClient, expressInstance = express()) => { +exports.createServer = (dynamodbClient, docClient, local, expressInstance = express()) => { const app = expressInstance app.set('json spaces', 2) app.set('view engine', 'ejs') @@ -77,7 +80,7 @@ exports.createServer = (dynamodbClient, docClient, expressInstance = express()) if (!dynamodbClient || !docClient) { if (!dynamodbClient) { - dynamodbClient = new DynamoDBClient(createAwsConfig()) + dynamodbClient = new DynamoDBClient(createAwsConfig(local)) } docClient = docClient || DynamoDBDocumentClient.from(dynamodbClient) From 250bc8dd67e98347bdb6344e49f0683118b5b99a Mon Sep 17 00:00:00 2001 From: Vikas Peri Date: Wed, 22 Nov 2023 16:04:54 +0800 Subject: [PATCH 3/4] Update READme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8b19b47..596dd60 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Options: - --open / -o - opens server URL in a default browser on start - --port PORT / -p PORT - Port to run on (default: 8001) - --host HOST / -h HOST - Host to run on (default: localhost) + - --dummy_creds -D - To run with no AWS credentials(default: searches for local AWS credentials) You can specify host & port to run on by setting environment variables `HOST` and `PORT` respectively. This will override value specified on the command line. This is legacy way to specify the HOST & PORT. From f1b989464334171893f14b2eae3785749bb29192 Mon Sep 17 00:00:00 2001 From: Vikas Peri Date: Thu, 23 Nov 2023 10:47:50 +0800 Subject: [PATCH 4/4] default to use dummy creds --- README.md | 2 +- bin/dynamodb-admin.js | 7 ++++--- lib/backend.js | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 596dd60..afb748a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Options: - --open / -o - opens server URL in a default browser on start - --port PORT / -p PORT - Port to run on (default: 8001) - --host HOST / -h HOST - Host to run on (default: localhost) - - --dummy_creds -D - To run with no AWS credentials(default: searches for local AWS credentials) + - --local_config / -l - To use the locally configured AWS credentials(default: uses dummy credentials) You can specify host & port to run on by setting environment variables `HOST` and `PORT` respectively. This will override value specified on the command line. This is legacy way to specify the HOST & PORT. diff --git a/bin/dynamodb-admin.js b/bin/dynamodb-admin.js index 7356bc9..26a60eb 100755 --- a/bin/dynamodb-admin.js +++ b/bin/dynamodb-admin.js @@ -38,15 +38,16 @@ parser.add_argument('-p', '--port', { help: 'Port to run on (default: 8001)', }) -parser.add_argument('-D', '--dummy_creds', { +parser.add_argument('-l', '--local_config', { action:'store_true', required: false, - help: 'Use dummy AWS credentials', + default: false, + help: 'Use local AWS credentials', }) const args = parser.parse_args() -const app = createServer(undefined,undefined, args.dummy_creds) +const app = createServer(undefined,undefined, args.local_config) const host = process.env.HOST || args.host const port = process.env.PORT || args.port const server = app.listen(port, host) diff --git a/lib/backend.js b/lib/backend.js index e96bb21..2411e92 100644 --- a/lib/backend.js +++ b/lib/backend.js @@ -46,33 +46,33 @@ function loadDynamoEndpoint(env, dynamoConfig) { * @param AWS - the AWS SDK object * @returns {{endpoint: string, sslEnabled: boolean, region: string, accessKeyId: string}} */ -function loadDynamoConfig(env, isDummy) { +function loadDynamoConfig(env, local_config) { let dynamoConfig = { endpoint: 'http://localhost:8000', sslEnabled: false } - const dummy_creds = isDummy ? {credentials: { + const dummy_creds = local_config ? {}: {credentials: { accessKeyId: 'key', secretAccessKey: 'secret', region: 'us-east-1', - }}: {} - dynamoConfig = {...dynamoConfig, ...dummy_creds} + }} + dynamoConfig = {local_config, ...dynamoConfig, ...dummy_creds} loadDynamoEndpoint(env, dynamoConfig) return dynamoConfig } -const createAwsConfig = (isDummy) => { +const createAwsConfig = (local_config) => { const env = process.env - const dynamoConfig = loadDynamoConfig(env, isDummy) + const dynamoConfig = loadDynamoConfig(env, local_config) console.log(clc.blackBright(` database endpoint: \t${dynamoConfig.endpoint}`)) return dynamoConfig } -exports.createServer = (dynamodbClient, docClient, local, expressInstance = express()) => { +exports.createServer = (dynamodbClient, docClient, local_config, expressInstance = express()) => { const app = expressInstance app.set('json spaces', 2) app.set('view engine', 'ejs') @@ -80,7 +80,7 @@ exports.createServer = (dynamodbClient, docClient, local, expressInstance = expr if (!dynamodbClient || !docClient) { if (!dynamodbClient) { - dynamodbClient = new DynamoDBClient(createAwsConfig(local)) + dynamodbClient = new DynamoDBClient(createAwsConfig(local_config)) } docClient = docClient || DynamoDBDocumentClient.from(dynamodbClient)