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

Not starting DDB-local when running sls offline

Open revmischa opened this issue 3 years ago • 5 comments

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

revmischa avatar Sep 07 '20 14:09 revmischa

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

mdepascale avatar Oct 22 '20 16:10 mdepascale

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

kaskelotti avatar Nov 25 '20 08:11 kaskelotti

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

itsUnsmart avatar Feb 14 '21 23:02 itsUnsmart

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

coreyar avatar May 15 '21 13:05 coreyar

# ✅ 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.

say8425 avatar Oct 10 '21 10:10 say8425