Skip to content

Instantly share code, notes, and snippets.

@BuonOmo
Last active September 8, 2023 15:07
Show Gist options
  • Select an option

  • Save BuonOmo/f415466c4af38f236c11d879099af7cf to your computer and use it in GitHub Desktop.

Select an option

Save BuonOmo/f415466c4af38f236c11d879099af7cf to your computer and use it in GitHub Desktop.
Delete all items in a dynamo db table
#!/usr/bin/env zsh
# I'm using jq to parse json. I really suggest using it.
# I'm using parallel for faster results, you could use xargs or a for loop if you don't have parallel.
main() (
set -eux
local options="--profile some-profile"
local key='id'
local table='table'
local keys_json=$(aws $options dynamodb scan --table-name $table --attributes-to-get $key | jq --compact-output '.Items[]')
# Parallel uses "\n" as a delimiter. So as long as none of you strings contains a "\n", you'll be ok.
[[ $#keys_json > 0 ]] && parallel "aws $options dynamodb delete-item --table-name $table --key" ::: "$keys_json"
)
main
@BuonOmo

BuonOmo commented Jun 29, 2023

Copy link
Copy Markdown
Author

@raulvc it looks like cool but not necessary, could you tell me why you use that ? (my string already has a space in it and it is working quite well afaik!)

@ic

ic commented Sep 7, 2023

Copy link
Copy Markdown

Thank you for sharing this script. Does it really delete all items, or just the first 1000 max (or 1MB worth of data)?

@BuonOmo

BuonOmo commented Sep 8, 2023

Copy link
Copy Markdown
Author

@ic I'm not sure woudl it would behave like you said ^^. It used to delete all, nowadays I don't know.

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