Skip to content

Commit 8fc3242

Browse files
committed
Added seeding online tables functionality
1 parent 3a10a44 commit 8fc3242

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

index.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ class ServerlessDynamodbLocal {
2222
},
2323
seed: {
2424
lifecycleEvents: ["seedHandler"],
25-
usage: "Seeds local DynamoDB tables with data"
25+
usage: "Seeds local DynamoDB tables with data",
26+
options: {
27+
online: {
28+
shortcut: "o",
29+
usage: "Will connect to the tables online to do an online seed run"
30+
}
31+
}
2632
},
2733
start: {
2834
lifecycleEvents: ["startHandler"],
@@ -113,13 +119,23 @@ class ServerlessDynamodbLocal {
113119
return host;
114120
}
115121

116-
dynamodbOptions() {
117-
const dynamoOptions = {
118-
endpoint: `http://${this.host}:${this.port}`,
119-
region: "localhost",
120-
accessKeyId: "MOCK_ACCESS_KEY_ID",
121-
secretAccessKey: "MOCK_SECRET_ACCESS_KEY"
122-
};
122+
dynamodbOptions(options) {
123+
let dynamoOptions = {};
124+
125+
if(options && options.online){
126+
this.serverlessLog("Connecting to online tables...");
127+
if (!options.region) throw new Error("please specify the region");
128+
dynamoOptions = {
129+
region: options.region,
130+
};
131+
} else {
132+
dynamoOptions = {
133+
endpoint: `http://${this.host}:${this.port}`,
134+
region: "localhost",
135+
accessKeyId: "MOCK_ACCESS_KEY_ID",
136+
secretAccessKey: "MOCK_SECRET_ACCESS_KEY"
137+
};
138+
}
123139

124140
return {
125141
raw: new AWS.DynamoDB(dynamoOptions),
@@ -134,7 +150,8 @@ class ServerlessDynamodbLocal {
134150
}
135151

136152
seedHandler() {
137-
const documentClient = this.dynamodbOptions().doc;
153+
const options = this.options;
154+
const documentClient = this.dynamodbOptions(options).doc;
138155
const seedSources = this.seedSources;
139156
return BbPromise.each(seedSources, (source) => {
140157
if (!source.table) {

0 commit comments

Comments
 (0)