Skip to content

Commit 94814d4

Browse files
authored
Merge pull request #157 from keshav1002/v1
Added functionality to seed tables that are deployed online
2 parents 3a10a44 + 1ff1438 commit 94814d4

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

index.js

Lines changed: 28 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,25 @@ 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) {
128+
throw new Error("please specify the region");
129+
}
130+
dynamoOptions = {
131+
region: options.region,
132+
};
133+
} else {
134+
dynamoOptions = {
135+
endpoint: `http://${this.host}:${this.port}`,
136+
region: "localhost",
137+
accessKeyId: "MOCK_ACCESS_KEY_ID",
138+
secretAccessKey: "MOCK_SECRET_ACCESS_KEY"
139+
};
140+
}
123141

124142
return {
125143
raw: new AWS.DynamoDB(dynamoOptions),
@@ -134,7 +152,8 @@ class ServerlessDynamodbLocal {
134152
}
135153

136154
seedHandler() {
137-
const documentClient = this.dynamodbOptions().doc;
155+
const options = this.options;
156+
const documentClient = this.dynamodbOptions(options).doc;
138157
const seedSources = this.seedSources;
139158
return BbPromise.each(seedSources, (source) => {
140159
if (!source.table) {

0 commit comments

Comments
 (0)