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

Rely on docker for local dynamodb

Open jbremmer opened this issue 7 years ago • 15 comments

Could this plugin switch to relying on docker or better yet docker-compose so I would have to have blobal JDK installation for DynamoDB?

jbremmer avatar Dec 13 '16 17:12 jbremmer

You should be able to use a docker container. Skip the first two steps(sls dynamodb install & sls dynamodb start) which installs and starts dynamodb locally. Declare a custom port if the container uses a different port than 8000 for dynamodb by configuring it in serverless.yml

AshanFernando avatar Dec 15 '16 04:12 AshanFernando

That's how I'm doing this, would be nice though to have it in package.

jbremmer avatar Dec 15 '16 13:12 jbremmer

I'm using dockerized ddb and node app (combined in docker-compose). Can I just use the "migrate" functionality of this plugin? When entering the apps container and doing a ./node_modules/.bin/serverless dynamodb migrate, I get [SyntaxError: Unexpected token C]

bebbi avatar Mar 16 '17 14:03 bebbi

Turns out the above syntax error is a side effect of a request that fails to reach ddb and returns Cannot POST /

bebbi avatar Mar 22 '17 14:03 bebbi

In case it's helpful to anyone coming from a Google search for "serverless dynamodb local with Docker", this configuration let's you find the right docker container, skip the plugin's startup step and run a migration:

custom:
  dynamodb:
    start:
      host: dynamo # or the name of your Dynamo docker container
      port: "8000" # the port of our Dynamo docker container
      noStart: true
      migrate: true

kjersten avatar Jun 30 '19 03:06 kjersten

I had to specify the image instead of host:

custom:
  dynamodb:
    start:
      image: dynamo # or the name of your Dynamo docker container
      port: "8000" # the port of our Dynamo docker container
      noStart: true
      migrate: true

cyberwombat avatar Aug 29 '19 15:08 cyberwombat

@kjersten Thank you so much, your little snippet worked. One thing that bothers me is that I only have on file serverless.yml, so I am unsure how that change in serverless.yml will affect production. In production I just want all the custom stuff to be ignored.

AntonioCS avatar Mar 04 '20 10:03 AntonioCS

@AntonioCS you can specify which stage this runs on:

dynamodb:
  # If you only want to use DynamoDB Local in some stages, declare them here
    stages:
      - dev

Is that what you need?

cyberwombat avatar Mar 04 '20 15:03 cyberwombat

I am running successfully a container with dynamodb-local. It also seems the migration and seed are correctly performed, but at the moment my tests run, they do not find any table. Here is the error I get:

Cannot do operations on a non-existent table

I have checked the DB vía web and, certainly, there is nothing.

Has anyone a hint?

kazbeel avatar Mar 11 '20 10:03 kazbeel

@cyberwombat Thanks but I just created another serverless.yml file and just pass that to serveless with the -c option.

AntonioCS avatar Mar 11 '20 11:03 AntonioCS

I am running successfully a container with dynamodb-local. It also seems the migration and seed are correctly performed, but at the moment my tests run, they do not find any table. Here is the error I get:

Cannot do operations on a non-existent table

I have checked the DB vía web and, certainly, there is nothing.

Has anyone a hint?

I am also having this problem. The weird thing is that if I execute a shell in the container running the serverless application and run sls dynamodb migrate --account local --port 8000 --host dynamodb the output is:

Serverless: DynamoDB - Warn - table xxxxx already exists
Serverless: DynamoDB - Warn - table xxxxx already exists
Serverless: DynamoDB - Warn - table xxxxx already exists

But my app still says it does not have the tables created. Even, if I go to the shell, no table has been created. Very weird.

jorchg avatar Apr 04 '20 21:04 jorchg

@jorchg Could you have possibly installed DynamoDB local as well? Perhaps you have both a local instance and a docker instance running

cyberwombat avatar Apr 04 '20 21:04 cyberwombat

@jorchg Could you have possibly installed DynamoDB local as well? Perhaps you have both a local instance and a docker instance running

I have just found that I have to start the dynamodb-local docker image with the -inMemory and -sharedDb options, in my docker-compose.yml file just like this:

 dynamodb:
    image: 'amazon/dynamodb-local'
    ports:
      - '8000:8000'
    command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"]

That solved the problem :)

jorchg avatar Apr 04 '20 22:04 jorchg

@jorchg Could you have possibly installed DynamoDB local as well? Perhaps you have both a local instance and a docker instance running

I have just found that I have to start the dynamodb-local docker image with the -inMemory and -sharedDb options, in my docker-compose.yml file just like this:

 dynamodb:
    image: 'amazon/dynamodb-local'
    ports:
      - '8000:8000'
    command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-inMemory"]

That solved the problem :)

The option "in memory" seems to be active by default in the docker image, but it is the "share DB" which makes the trick... Thanks for your help!

kazbeel avatar Apr 06 '20 11:04 kazbeel

just to be clear if anyone gets here - with @kjersten custom.dynamo config it's still required to run sls dynamodb migrate to get the tables created

ciekawy avatar Jun 21 '21 21:06 ciekawy