Skip to content

Commit 5057b82

Browse files
author
Calle Kabo
committed
this works better
1 parent c275693 commit 5057b82

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ All the above options can be added to serverless.yml to set default configuratio
6060
```yml
6161
custom:
6262
dynamodb:
63+
# If you only want to use DynamoDB Local in some stages, declare them here
64+
stages:
65+
- dev
6366
start:
6467
port: 8000
6568
inMemory: true
6669
migrate: true
6770
seed: true
6871
# Uncomment only if you already have a DynamoDB running locally
6972
# noStart: true
70-
# If you only want to start DynamoDB in some stages, declare them here
71-
stages:
72-
- dev
7373
```
7474

7575
## Migrations: sls dynamodb migrate

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class ServerlessDynamodbLocal {
9696
}
9797
};
9898

99+
const stage = this.options.stage || this.service.provider.stage
100+
if (this.config.stages && !this.config.stages.includes(stage)) {
101+
// don't do anything for this stage
102+
this.hooks = {}
103+
return
104+
}
105+
99106
this.hooks = {
100107
"dynamodb:migrate:migrateHandler": this.migrateHandler.bind(this),
101108
"dynamodb:seed:seedHandler": this.seedHandler.bind(this),
@@ -182,16 +189,9 @@ class ServerlessDynamodbLocal {
182189
this.options
183190
);
184191

185-
const stage = options.stage || this.serverless.service.provider.stage
186-
let startThisStage = true;
187-
if (options.stages && !options.stages.includes(stage)) {
188-
startThisStage = false;
189-
}
190-
options.startThisStage = startThisStage
191-
192192
// otherwise endHandler will be mis-informed
193193
this.options = options;
194-
if (!options.noStart && startThisStage) {
194+
if (!options.noStart) {
195195
dynamodbLocal.start(options);
196196
}
197197
return BbPromise.resolve()
@@ -200,7 +200,7 @@ class ServerlessDynamodbLocal {
200200
}
201201

202202
endHandler() {
203-
if (!this.options.noStart && this.options.startThisStage) {
203+
if (!this.options.noStart) {
204204
this.serverlessLog("DynamoDB - stopping local database");
205205
dynamodbLocal.stop(this.port);
206206
}

0 commit comments

Comments
 (0)