Is it possible to export data from DynamoDB table in some format?
The concrete use case is that I want to export data from my production dynamodb database and import
Here is a way to export some datas (oftentime we just want to get a sample of our prod data locally) from a table using aws cli and jq.
Let's assume we have a prod table called unsurprisingly my-prod-table and a local table called my-local-table
To export the data run the following:
aws dynamodb scan --table-name my-prod-table \
| jq '{"my-local-table": [.Items[] | {PutRequest: {Item: .}}]}' > data.json
Basically what happens is that we scan our prod table, transform the output of the scan to shape into the format of the batchWriteItem and dump the result into a file.
To import the data in your local table run:
aws dynamodb batch-write-item \
--request-items file://data.json \
--endpoint-url http://localhost:8000
Note: There are some restriction with the batch-write-item request - The BatchWriteItem operation can contain up to 25 individual PutItem and DeleteItem requests and can write up to 16 MB of data. (The maximum size of an individual item is 400 KB.).