Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on docker for local dynamodb #57

Open
jbremmer opened this issue Dec 13, 2016 · 15 comments
Open

Rely on docker for local dynamodb #57

jbremmer opened this issue Dec 13, 2016 · 15 comments

Comments

@jbremmer
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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

@bebbi
Copy link

bebbi commented Mar 16, 2017

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
Copy link

bebbi commented Mar 22, 2017

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

@kjersten
Copy link

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
Copy link

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
Copy link

@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
Copy link

@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
Copy link

kazbeel commented Mar 11, 2020

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
Copy link

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

@jorchg
Copy link

jorchg commented Apr 4, 2020

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
Copy link

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

@jorchg
Copy link

jorchg commented Apr 4, 2020

@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
Copy link

kazbeel commented Apr 6, 2020

@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
Copy link

ciekawy commented Jun 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants