2
votes

I want to connect the db available inside DynamoDbLocal using the boto sdk.I followed the documentation as per the below link.

http://boto.readthedocs.org/en/latest/dynamodb2_tut.html#dynamodb-local

This is the official documentation provided by the amazon.But when I am executing the snippet available in the document, I am unable to connect the db and I can't get the tables available inside the db. The dbname is "dummy_us-east-1.db". And my snippet is:

from boto.dynamodb2.layer1 import DynamoDBConnection
con = DynamoDBConnection(host='localhost', port=8000,
    aws_access_key_id='dummy',
    aws_secret_access_key='dummy',
    is_secure=False,
    )

print con.list_tables()

I have a 8 tables available inside the db. But I am getting empty list, after executing the list_tables() command.

output:
{u'TableNames':[]}

Instead of accessing the required database, it creating and accessing the new database. Old database : dummy_us-east-1.db New database : dummy_localhost.db How to resolve this. Please give me some suggestions regarding to the DynamoDbLocal access. Thanks in advance.

2
Can you show the show the code where you are calling CreateTable? - mkobit
It looks as though you are connecting correctly to DynamoDBLocal. I'm wondering how did you create the tables in the dummy_us-east-1.db file? Have you tried a create table call yet and verified that list_tables is still empty? users = Table.create('users', schema=[HashKey('username')], connection=con); - Raymond Lin
Hi @MikeKobit it's just a python code using the boto sdk. The above snippet is my code.By using that code we are able to connect the localdynamodb. - bhadram
@bhadramkomali you need to actually create the tables in the DynamoDB local database. You are connected to it, but nothing is there yet because you haven't put it there. - mkobit
Hi @RaymondLin thanks for your quick response. What problem I am getting after the table creation is that I was unable to see the tables in the db what I have mentioned in the question. After creating the tables I am able to get the tables list {u'TableNames': [u'sample', u'users']} like this. But once I restarted the system the tables are disappeared and those tables were not even available in the db also. And one more thing that the tables creation working is fine, but the insertion of data into the tale is giving some problems. And mainly I want to focus on the table creation in the db. - bhadram

2 Answers

1
votes

It sounds like you are using different approaches to connect to DynamoDB Local.

If so, you can also start DynamoDB Local with the sharedDb flag to force it to use a single db file:

-sharedDb                   When specified, DynamoDB Local will use a
                            single database instead of separate databases
                            for each credential and region. As a result,
                            all clients will interact with the same set of
                            tables, regardless of their region and
                            credential configuration.

E.g.

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar --sharedDb
1
votes

Here is the solution. this is because you didn't start the dynamodb with it location of jar file.

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb