99x / serverless-dynamodb-local

Serverless Dynamodb Local Plugin - Allows to run dynamodb locally for serverless
MIT License
624 stars 234 forks source link

Not starting DDB-local when running sls offline #256

Open revmischa opened 4 years ago

revmischa commented 4 years ago

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

mdepascale commented 4 years ago

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

kaskelotti commented 3 years ago

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
itsUnsmart commented 3 years ago

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

coreyar commented 3 years ago

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

say8425 commented 3 years ago
# ✅ 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.