dynamo db local shell doesn't list tables using docker image
Asked Answered
E

3

17

I am using docker enabled dynamoDB local as mentioned here

and following is my JS code:

AWS.config.update({
  region: 'sas',
  endpoint:  'http://docker.for.mac.host.internal:8000' //'http://localhost:8000'
});

and create table function below:

function createTable() {
    let params = {
        TableName: 'sas',
        KeySchema: [{
            AttributeName: 'title',
            KeyType: 'HASH',
        }],
        AttributeDefinitions: [{
            AttributeName: 'title',
            AttributeType: 'S'
        }],
        ProvisionedThroughput: {
            ReadCapacityUnits: 1,
            WriteCapacityUnits: 1,
        }
    };
    dynamoDB.createTable(params, function(err, data) {
        if (err)
            console.log(err); // an error occurred
        else
            console.log(data);
    });
}   

i could see created table sas using cli :

aws dynamodb list-tables --endpoint-url http://localhost:8000 --region=sas  

but NOT listing the table in the and it's always empty.

http://localhost:8000/shell/

any idea's?

NOTE: i can see my table with above code, by running dynamodb jar locally

 java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb 
Ebonieebonite answered 15/2, 2019 at 23:23 Comment(1)
for me, what did the trick was to check the region in my .aws\config file and set it the same as the one you mention in your JS code - sas (for me it is set to eu-west-2), maybe it helps someone ...Surpass
E
17

make sure you are also passing -sharedDb to the docker image.

If -sharedDb is not present then dynamodb-local will use
access keys+region as namespaces to separate tables
(as if they were under different aws accounts)

Ethelda answered 16/2, 2019 at 19:23 Comment(4)
It wouldn't work for me by just adding -sharedDb to the Docker run command. I had to use docker run -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDbVentage
@andyberry88 great, this finally worked! Also don't forget you have to re-create the tables after you first started with -sharedDb.Roughneck
I was trying to do it with docker-compose instead but couldn't find a way to have the tables listed in the /shell. Running it with docker directly worked.Spiderwort
I was able to do it with docker compose. I overrode the command like this: command: -jar DynamoDBLocal.jar -sharedDbCatcall
W
15

As @Mendhak points out in the comments on another answer here, if you are using docker-compose, you will need to share the db, which you can do by overriding the command in docker-compose.yml

version: "3.7"
services:
  dynamodb-local:
    image: amazon/dynamodb-local:latest
    container_name: dynamodb-local
    ports:
      - "8000:8000"
    command: -jar DynamoDBLocal.jar -sharedDb

I didn't see this anywhere in the sprawling AWS docs, so I wanted to leave this answer to improve visibility for other wandering devs.

Credit to Mendhak - you could upvote his comment as well as this answer, if it helped you!

Waxwork answered 15/7, 2020 at 21:35 Comment(0)
H
4

You can specify -sharedDb param when start docker dynamodb.

docker run -itd -p 8000:8000  --name dev-db amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb
Halide answered 1/6, 2021 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.