diff --git a/src/db-wrapper.js b/src/db-wrapper.js index c51de1e4..31e716ed 100644 --- a/src/db-wrapper.js +++ b/src/db-wrapper.js @@ -13,10 +13,14 @@ import createDynamoDBService from './db.js'; import serviceWrap from './service-wrap.js'; function wrapper(func) { + const region = process.env.AWS_REGION; + if (!region) { + throw Error('Please define region in secrets'); + } return (request, context) => serviceWrap( func, request, - context, + { ...context, region }, '__ow_dynamodb', createDynamoDBService, ); diff --git a/src/db.js b/src/db.js index 787818a4..ce895556 100644 --- a/src/db.js +++ b/src/db.js @@ -16,8 +16,8 @@ import { log } from './util.js'; const TABLE_SITES = 'spacecat-site'; const TABLE_AUDITS = 'spacecat-audit-index'; -function DB() { - const client = new DynamoDBClient({ region: process.env.REGION }); +function DB(context) { + const client = new DynamoDBClient({ region: context.region }); const docClient = DynamoDBDocumentClient.from(client); /** @@ -136,6 +136,6 @@ function DB() { }; } -const createDynamoDBService = () => DB(); +const createDynamoDBService = (context) => DB(context); export default { createDynamoDBService };