serverless-dynamodb-local icon indicating copy to clipboard operation
serverless-dynamodb-local copied to clipboard

Doesn't start automatically with Serverless Offline

Open simonsayscode opened this issue 8 years ago • 5 comments
trafficstars

The serverless dynamodb start command can be triggered automatically when using serverless-offline plugin.

In trying to run https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb-and-offline as an example, it doesn't seem like serverless-dynamodb-local is being started by serverless offline hooks.

I see these lines from https://github.com/99xt/serverless-dynamodb-local/blob/v1/index.js#L94: "before:offline:start:init": this.startHandler.bind(this), "before:offline:start:end": this.endHandler.bind(this),

But they don't seem to trigger the startHandler.

node v.6.10.0 serverless 1.11.0 serverless-dynamodb-local 0.2.18 serverless-offline 3.8.3

simonsayscode avatar Apr 20 '17 20:04 simonsayscode

I've seen this same issue. To get around it, i was starting dynamodb local manually, then running serverless offline.

Start dynamo manually: sls dynamodb start --migrate

Then start your app: sls offline

Aggiemaster avatar Apr 24 '17 01:04 Aggiemaster

Yeah, that's the workaround I've been using too. This definitely isn't a blocker but I just wanted to highlight it since it goes contrary to what the documentation says.

simonsayscode avatar Apr 24 '17 03:04 simonsayscode

Just use serverless offline start. Dynamodb is not triggered when using the command without start.

nenti avatar Apr 26 '17 07:04 nenti

Thanks for the update @nenti.

I was able to use: sls offline start --migrate

Quick question though on the custom fields in the serverless.yml file. I have the following in my file, so I would assume I would not have to include the --migrate in the command since migration was set to true.

custom: dynamodb: start: port: 8000 inMemory: true migration: true migration: dir: offline/migrations

Currently, if I do not include the --migrate, the dynamo table will not be created.

Aggiemaster avatar Apr 26 '17 20:04 Aggiemaster

@Aggiemaster The serverless.yml setting to set migration on startup by default is migrate not migration. Not sure whether this includes the setting to point towards a migrations folder or not.

Had this problem myself so I'm guessing it is or was written down in documentation wrongly somewhere or some tutorial had it as migration.

EDIT: This seems to only work when specifying the tables to migrate in your serverless settings, not from a json file. (may have worked at the time the issue was reported) As per the documentation on the flags:

--migrate -m After starting DynamoDB local, create DynamoDB tables from the Serverless configuration.

Seeing this I'm guessing support for migrating from a json file may have been dropped.

M-TGH avatar Nov 10 '17 07:11 M-TGH