@@ -22,7 +22,13 @@ class ServerlessDynamodbLocal {
22
22
} ,
23
23
seed : {
24
24
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
+ }
26
32
} ,
27
33
start : {
28
34
lifecycleEvents : [ "startHandler" ] ,
@@ -113,13 +119,23 @@ class ServerlessDynamodbLocal {
113
119
return host ;
114
120
}
115
121
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
+ }
123
139
124
140
return {
125
141
raw : new AWS . DynamoDB ( dynamoOptions ) ,
@@ -134,7 +150,8 @@ class ServerlessDynamodbLocal {
134
150
}
135
151
136
152
seedHandler ( ) {
137
- const documentClient = this . dynamodbOptions ( ) . doc ;
153
+ const options = this . options ;
154
+ const documentClient = this . dynamodbOptions ( options ) . doc ;
138
155
const seedSources = this . seedSources ;
139
156
return BbPromise . each ( seedSources , ( source ) => {
140
157
if ( ! source . table ) {
0 commit comments