@@ -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