serverless-dynamodb-local
serverless-dynamodb-local copied to clipboard
Not starting DDB-local when running sls offline
Actual Behaviour
Not starting local dynamo when running sls offline
Steps to reproduce it
plugins:
- serverless-plugin-typescript
- serverless-plugin-optimize
- serverless-pseudo-parameters
- serverless-dynamodb-local
- serverless-offline
custom:
serverless-offline:
useChildProcesses: true
dynamodb:
start: # why doesn't this automatically start?
port: 4455
# inMemory: true
migrate: true
stages:
- dev
LogCat for the issue
Provide logs for the crash here
❯ sls offline
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Typescript compiled.
Serverless: Watching typescript files...
offline: Starting Offline: dev/eu-west-1.
offline: Offline [http for lambda] listening on http://localhost:3002
┌─────────────────────────────────────────────────────────────────────────────────┐
│ │
│ POST | http://localhost:3000/dev...... │ │
└─────────────────────────────────────────────────────────────────────────────────┘
offline: [HTTP] server ready: http://localhost:3000 🚀
offline:
offline: Enter "rp" to replay the last request
Would you like to work on the issue?
Not sure where to start
Alright finally I found out a method (it's very raw) to locally test dynamodb
I have this version:
"serverless-dynamodb-local": "^0.2.37"
serverless.yml custom parameters:
dynamodb:
stages:
- ${self:provider.stage}
start:
port: 8000
inMemory: true
migrate: true
#noStart: true
migration:
dir: offline/migrations
My lambda runs this configuration:
let options = {};
if (process.env.IS_OFFLINE) {
options = {
endpoint: 'http://localhost:8000',
region: 'localhost'
}
}
const dynamodb = new DynamoDB.DocumentClient(options);
after that I run serverless dynamodb start --stage local
in one shell
and sls offline --stage local
in the other one
This works, it's the first solution that worked for me, I will try to improve it in the meantime you could use this one
I've had some issue similar to this that were fixed by setting the correct order of plugins in serverless.yml file. Put serverless-offline before dynamodb, i.e. like below
plugins:
- ...
- serverless-offline
- serverless-dynamodb-local
Yeah, same issue here... you can start it with sls dynamodb start
but really needs to auto start with serverless-offline.
Edit: it seems I have found the solution... run serverless offline with the command: serverless offline start
I've had some issue similar to this that were fixed by setting the correct order of plugins in serverless.yml file. Put serverless-offline before dynamodb, i.e. like below
plugins: - ... - serverless-offline - serverless-dynamodb-local
According to the docs serverless-offline
should be last
https://github.com/dherault/serverless-offline#usage-with-serverless-dynamodb-local-and-serverless-webpack-plugin
# ✅ works
sls offline start
serverless offline start
# ❌ not work
sls offline
serverless offline
sls offline
and serverless offline
dose not start dynamodb-local automatically.
But sls offline start
and serverless offline start
dose start dynamodb-local automatically.
Because serverless-dynamodb-local has hook with before:offline:start
.
So you need to add start
.