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

dbPath property not taking relative path from current directory

Open saumilsdk opened this issue 6 years ago • 9 comments

I am running dynamodb with local env. I have specified below configuration in serverless.yml. dynamodb: start: port: 8000 dbPath: .\tmp migrate: true migration: dir: offline/migrations I expected to get db file created under tmp directory created in local project. But it gave error.

Invalid directory for database creation.Serverless:

saumilsdk avatar Apr 08 '18 15:04 saumilsdk

the same here

chrkaatz avatar May 04 '18 19:05 chrkaatz

Seems to work if you give it full path to directory rather than a relative path.

So you do something like this on Mac

dbPath: ${env:PWD}/tmp

ptimson avatar May 13 '18 22:05 ptimson

This won't work in windows. And relative path works in other plugins like local S3.

saumilsdk avatar May 14 '18 05:05 saumilsdk

Yep I get this error no matter what I do. On macos

jamesoflol avatar May 18 '18 05:05 jamesoflol

dbPath: ${env:PWD}/tmp
This worked for me on Mac, if I mkdir tmp before starting it up sls offline start.

jordanboston avatar Aug 30 '18 18:08 jordanboston

@rehrumesh @mjzone Will you be able to have a look into this?

AshanFernando avatar Aug 31 '18 02:08 AshanFernando

still an issue. failed to use dbPath with a relative path. the pwd trick did it for me on osx

martinjuhasz avatar Feb 06 '20 08:02 martinjuhasz

make your dbPath as below.

dbPath: ${env:HOME}/dynamodb-local

mdrijwan avatar Oct 13 '20 07:10 mdrijwan

Looking at the code of the project, the relevent lines are:

let dbPath = options.dbPath;
if (dbPath) {
    options.dbPath = path.isAbsolute(dbPath) ? dbPath : path.join(this.serverless.config.servicePath, dbPath);
}

So if your path isn't absolute, it'll take it from the serverless config servicePath, which for me was <project root>/.build and not in node_modules as in the README

I created a new folder for my DB in my project root, and the following path works:

dbPath: ../.localdb_instance

divillysausages avatar Feb 07 '22 11:02 divillysausages