问题
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.
回答1:
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.
回答2:
For localhost dynamodb:
$aws dynamodb scan --table-name AOP --region us-east-1 --endpoint-url
http://localhost:8000 --output json > /home/ohelig/Desktop/a.json
For dynamodb:
$aws dynamodb scan --table-name AOP --region us-east-1 --output json > /home/ohelig/Desktop/a.json
Then Convert JSON to CSV or whatever.
I have modified above answer to make it clear.
回答3:
You can use jq convert the json output given by aws cli to csv
aws dynamodb scan --table-name mytable --query "Items[*].[id.S,name.S]" --output json | jq -r '.[] | @csv' > dump.csv
来源:https://stackoverflow.com/questions/33357821/how-to-export-a-dynamodb-table-as-a-csv-through-aws-cli-without-using-pipeline