Open jbremmer opened 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
That's how I'm doing this, would be nice though to have it in package.
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]
Turns out the above syntax error is a side effect of a request that fails to reach ddb and returns Cannot POST /
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
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
@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 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?
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?
@cyberwombat Thanks but I just created another serverless.yml
file and just pass that to serveless with the -c
option.
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 Could you have possibly installed DynamoDB local as well? Perhaps you have both a local instance and a docker instance running
@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 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 mydocker-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!
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
Could this plugin switch to relying on docker or better yet docker-compose so I would have to have blobal JDK installation for DynamoDB?