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 
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 ... Commented Mar 16, 2021 at 6:51

3 Answers 3

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)

Sign up to request clarification or add additional context in comments.

4 Comments

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 -sharedDb
@andyberry88 great, this finally worked! Also don't forget you have to re-create the tables after you first started with -sharedDb.
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.
I was able to do it with docker compose. I overrode the command like this: command: -jar DynamoDBLocal.jar -sharedDb
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!

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.