Skip to content

Instantly share code, notes, and snippets.

@ak-git
Created December 20, 2024 06:42
Show Gist options
  • Save ak-git/b032915b72fed02f4cc8c7500d97b7c2 to your computer and use it in GitHub Desktop.
Save ak-git/b032915b72fed02f4cc8c7500d97b7c2 to your computer and use it in GitHub Desktop.
Dynamo db export to csv
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
@ak-git
Copy link
Author

ak-git commented Dec 20, 2024

aws dynamodb scan --table-name CyberBase --select ALL_ATTRIBUTES --page-size 500 --max-items 100000 --output json > CyberBase.json

@ak-git
Copy link
Author

ak-git commented Dec 20, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment