Skip to content

Commit c275693

Browse files
author
Calle Kabo
committed
can whitelist stages to start dynamodb local
1 parent 52c5497 commit c275693

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ custom:
6767
seed: true
6868
# Uncomment only if you already have a DynamoDB running locally
6969
# noStart: true
70+
# If you only want to start DynamoDB in some stages, declare them here
71+
stages:
72+
- dev
7073
```
7174

7275
## Migrations: sls dynamodb migrate

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,16 @@ class ServerlessDynamodbLocal {
182182
this.options
183183
);
184184

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+
185192
// otherwise endHandler will be mis-informed
186193
this.options = options;
187-
if (!options.noStart) {
194+
if (!options.noStart && startThisStage) {
188195
dynamodbLocal.start(options);
189196
}
190197
return BbPromise.resolve()
@@ -193,7 +200,7 @@ class ServerlessDynamodbLocal {
193200
}
194201

195202
endHandler() {
196-
if (!this.options.noStart) {
203+
if (!this.options.noStart && this.options.startThisStage) {
197204
this.serverlessLog("DynamoDB - stopping local database");
198205
dynamodbLocal.stop(this.port);
199206
}

0 commit comments

Comments
 (0)