Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 229
Sasi Kathimanda Avatar asked Feb 15 '19 23:02

Sasi Kathimanda


3 Answers

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!

like image 66
Soft Bullets Avatar answered Nov 20 '22 14:11

Soft Bullets


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
like image 40
Freax Avatar answered Nov 20 '22 14:11

Freax


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)

like image 15
Adrian Praja Avatar answered Nov 20 '22 14:11

Adrian Praja