How to export a dynamodb table as a csv through aws-cli ( without using pipeline)

Vibhor Nigam picture Vibhor Nigam · Oct 27, 2015 · Viewed 30.5k times · Source

I am new to aws-cli and I am trying to export my dynamodb table as a csv so that i can import it directly into postgresql. Is there a way to do that using aws-cli ?

So far i have came across this command aws dynamodb scan --table-name . But this does not provide an option of a csv export. Also, through this command I can get the output on my command prompt but I am not sure how to write it in a file.

Answer

jarmod picture jarmod · Oct 27, 2015

If all items have the same attributes, e.g. id and name both of which are strings, then run:

aws dynamodb scan \
    --table-name mytable \
    --query "Items[*].[id.S,name.S]" \
    --output text

That would give tab-separated output. You can redirect this to file using > output.txt, and you could then easily convert tabs into commas for csv.

Another option is the DynamoDBtoCSV project at github.