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

前端 未结 4 988
陌清茗
陌清茗 2020-12-13 09:51

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 ?

相关标签:
4条回答
  • 2020-12-13 10:09

    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
    
    0 讨论(0)
  • 2020-12-13 10:10

    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.

    0 讨论(0)
  • 2020-12-13 10:11

    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.

    0 讨论(0)
  • 2020-12-13 10:18

    A better way to do a full export of all columns without listign out is at Dynamo db export to csv

    basically

    aws dynamodb scan --table-name my-table --select ALL_ATTRIBUTES --page-size 500 --max-items 100000 --output json | jq -r '.Items' | jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ].S])[] | @csv' > export.my-table.csv
    
    0 讨论(0)
提交回复
热议问题