99x / serverless-dynamodb-local

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

Rely on docker for local dynamodb #57

Open jbremmer opened 7 years ago

jbremmer commented 7 years ago

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

AshanFernando commented 7 years ago

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

jbremmer commented 7 years ago

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

bebbi commented 7 years ago

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

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

kjersten commented 5 years ago

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
cyberwombat commented 5 years ago

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
AntonioCS commented 4 years ago

@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.

cyberwombat commented 4 years ago

@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?

kazbeel commented 4 years ago

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?

AntonioCS commented 4 years ago

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

jorchg commented 4 years ago

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.

cyberwombat commented 4 years ago

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

jorchg commented 4 years ago

@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 :)

kazbeel commented 4 years ago

@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!

ciekawy commented 3 years ago

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