Reputation: 6246
I have looked at several stackoverflow posts as well as the AWS docs for dynamodb to answer this question. I want to be able to run local dynamodb in docker and then connect to it from my locally running java app. I have installed the amazon/dynamodb-local image and have it working. I have even used the aws cli to create a table, list tables, delete tables etc on this locally running dynamodb. I got the dynamodb sdk dependency installed in the java project and I feel like I got everything wired up to work, ran an integration test and boom I get this error message
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Cannot do operations on a non-existent table (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: c915ea26-008e-4a9f-8b99-6df5d6aa7c5f)
The table does exist when run the list-tables function with the aws cli so I googled and then I checked the docs dynamodb docs and it seems like you have to start the local dynamodb with a flag
-sharedDb
I tried this by trying to start the locally running dynamodb with this command
docker run -p 8000:8000 amazon/dynamodb-local -sharedDb
Although I get the error
Unrecognized option: -sharedDb Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
I have tried googling after this or looking for somebody that has had a similar problem. But I find nothing. How can I start the locally running dynamodb and connect to it from my locally running java app?
Upvotes: 1
Views: 1631
Reputation: 11940
You need to write the command like this
docker run -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb
Don't forget that you might need to mount a volume in order to keep the data on the host as using the above command wont make the data saved if you have removed the container and to do this you need to use
-v
flag
docker run -p 8000:8000 -v /path/to/data/locally:/data/ amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb -dbPath /data
For more options you can use (note the --rm
flag)
docker run --rm -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -help
Upvotes: 5