Created
December 20, 2024 06:42
-
-
Save ak-git/b032915b72fed02f4cc8c7500d97b7c2 to your computer and use it in GitHub Desktop.
Dynamo db export to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws dynamodb scan \ | |
--table-name CyberBase \ | |
--select ALL_ATTRIBUTES \ | |
--page-size 500 \ | |
--max-items 100000 \ | |
--output json | \ | |
jq -r ' | |
def extract_value: | |
if type == "object" then | |
if .N != null then .N | |
elif .S != null then .S | |
elif .BOOL != null then .BOOL | |
elif .M != null then .M | |
else null end | |
else . end; | |
def flatten_item: | |
to_entries | map( | |
if .value.M != null then | |
(.value.M | to_entries | map({key: "out_\(.key)", value: .value | extract_value}))[] | |
else | |
{key: .key, value: (.value | extract_value)} | |
end | |
); | |
(.Items[0] | flatten_item | map(.key)) as $headers | | |
[$headers | .[]], | |
(.Items[] | flatten_item | map(.value)) | | |
@csv' > my-table-3.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://csvjson.com/