@@ -9,6 +9,7 @@ class ServerlessDynamodbLocal {
9
9
constructor ( serverless , options ) {
10
10
this . serverless = serverless ;
11
11
this . service = serverless . service ;
12
+ this . serverlessLog = serverless . cli . log . bind ( serverless . cli ) ;
12
13
this . config = this . service . custom && this . service . custom . dynamodb || { } ;
13
14
this . options = options ;
14
15
this . provider = "aws" ;
@@ -91,14 +92,19 @@ class ServerlessDynamodbLocal {
91
92
"dynamodb:install:installHandler" : this . installHandler . bind ( this ) ,
92
93
"dynamodb:start:startHandler" : this . startHandler . bind ( this ) ,
93
94
"before:offline:start:init" : this . startHandler . bind ( this ) ,
95
+ "before:offline:start:end" : this . endHandler . bind ( this ) ,
94
96
} ;
95
97
}
96
98
97
- dynamodbOptions ( ) {
99
+ get port ( ) {
98
100
const config = this . config ;
99
101
const port = _ . get ( config , "start.port" , 8000 ) ;
102
+ return port ;
103
+ }
104
+
105
+ dynamodbOptions ( ) {
100
106
const dynamoOptions = {
101
- endpoint : `http://localhost:${ port } ` ,
107
+ endpoint : `http://localhost:${ this . port } ` ,
102
108
region : "localhost" ,
103
109
accessKeyId : "MOCK_ACCESS_KEY_ID" ,
104
110
secretAccessKey : "MOCK_SECRET_ACCESS_KEY"
@@ -147,13 +153,16 @@ class ServerlessDynamodbLocal {
147
153
) ;
148
154
149
155
dynamodbLocal . start ( options ) ;
150
- console . log ( "" ) ; // separator
151
-
152
156
return BbPromise . resolve ( )
153
157
. then ( ( ) => options . migrate && this . migrateHandler ( ) )
154
158
. then ( ( ) => options . seed && this . seedHandler ( ) ) ;
155
159
}
156
160
161
+ endHandler ( ) {
162
+ this . serverlessLog ( 'DynamoDB - stopping local database' ) ;
163
+ dynamodbLocal . stop ( this . port ) ;
164
+ }
165
+
157
166
/**
158
167
* Gets the table definitions
159
168
*/
@@ -174,7 +183,7 @@ class ServerlessDynamodbLocal {
174
183
const seedConfig = _ . get ( config , "seed" , { } ) ;
175
184
const seed = this . options . seed ;
176
185
if ( ! seed ) {
177
- console . log ( " No seed option defined. Cannot seed data.") ;
186
+ this . serverlessLog ( "DynamoDB - No seed categories defined. Skipping data seeding .") ;
178
187
return [ ] ;
179
188
}
180
189
const categories = seed . split ( "," ) ;
@@ -186,10 +195,10 @@ class ServerlessDynamodbLocal {
186
195
return new BbPromise ( ( resolve , reject ) => {
187
196
dynamodb . raw . createTable ( migration , ( err ) => {
188
197
if ( err ) {
189
- console . log ( err ) ;
198
+ this . serverlessLog ( "DynamoDB - Error - " , err ) ;
190
199
reject ( err ) ;
191
200
} else {
192
- console . log ( "Table creation completed for table: " + migration . TableName ) ;
201
+ this . serverlessLog ( "DynamoDB - created table " + migration . TableName ) ;
193
202
resolve ( migration ) ;
194
203
}
195
204
} ) ;
0 commit comments