If I start local dynamodb first (sls dynamodb start -p 8000 --migrate true &), then start serverless offline, it always complains the port 8000 is used.
Seems serverless offline wants to take care local dynamodb starting.
But if I start serverless offline directly (sls offline start), it starts local dynamodb, but ignore the option --migrate true.
I confirm I have put the custom variables in serverless.yml already:
custom:
dynamodb:
start:
migrate: true
I also followed the instruction from example (https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb-and-offline), try to serverless dynamodb migrate
npm install
serverless dynamodb install
serverless offline start
serverless dynamodb migrate //(this imports schema)
get this error
$ serverless dynamodb migrate
Serverless: DynamoDB - Error -
Resource In Use Exception ------------------------------
Cannot create preexisting table
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 6.11.3
Serverless Version: 1.24.1
This should be posted in the dynamodb-local repo a serverless-offline doesn't really start dynamodb, dynamodb-local listens for the before:offline:start:init lifecycle event that offline creates.
Anyway, try the noStart config? docs here
As for the second thing: I've found that using the inMemory option for dynamodb-local is the best solution for avoiding errors including the preexisting table error, that way tables being seeded will definitely not exist as it's dropped every time serverless is ended. The only downside to this is longer wait times to start your serverless offline environment.
Thanks, @danbovey
I hope serverless-offline don't take care of dynamodb local, but in my testing, when sls offline start, it always try to start dynamodb local.
Any options to disable it?
So i figured this out @danbovey @ozbillwang
you need to start offline with the --noStart option
npx sls dynamodb start \
--port ${DYNAMODB_PORT} \
--host ${OFFLINE_HOST} \
--inMemory --migrate --seed &
npx sls offline start \
--host ${OFFLINE_HOST} \
--port ${LAMBDA_PORT} \
--noStart
Most helpful comment
So i figured this out @danbovey @ozbillwang
you need to start offline with the --noStart option