Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export an existing dynamo table schema to json?

I'd like to replicate some dynamodb tables, schema only, into my local environment for testing purposes. First I've tried:

aws dynamodb describe-table --table-name Foo > FooTable.json

But it's obvious that the output schema is not compliant to the input schema from the create-table command:

aws dynamodb create-table --cli-input-json file://FooTable.json --endpoint=http://localhost:8000

What I'm trying to avoid is to generate dozens of skeletons with aws dynamodb create-table --generate-cli-skeleton and fill them manually :/

Is there a way to get the table schema in a format that is "useful" for recreation? I find it unbelievable that there are no straightforward way of doing it through the web graphic interface or the standard aws command line - after hearing how "good" was their service.

like image 909
marcio Avatar asked Feb 07 '17 21:02

marcio


People also ask

How do I export a whole DynamoDB table?

To export a DynamoDB table, you use the AWS Data Pipeline console to create a new pipeline. The pipeline launches an Amazon EMR cluster to perform the actual export. Amazon EMR reads the data from DynamoDB, and writes the data to an export file in an Amazon S3 bucket.

Does DynamoDB return JSON?

The AWS SDKs use JSON to send data to DynamoDB, and DynamoDB responds with JSON.

Does DynamoDB store data in JSON?

You can store a JSON document as an attribute in a DynamoDB table. To do this, use the withJSON method of Item . This method parses the JSON document and maps each element to a native DynamoDB data type.


1 Answers

I just managed to do a complete dump and "restore" using bchew/dynamodump:

git clone [email protected]:bchew/dynamodump.git 

Notice the --schemaOnly option in the documentation https://github.com/bchew/dynamodump. Command was:

./dynamodump.py -m backup --schemaOnly --region foo-region --host localhost --srcTable '*' --port 8000 --accessKey fooKey --secretKey barKey 

Then you can use the -m restore mode to put the data or schema back into a local dynamodb or wherever desired :)

With that said, I still find it unbelievable how bad is the amazon dynamodb tool-chain. Come on guys.

like image 131
marcio Avatar answered Sep 22 '22 00:09

marcio