Last active
September 8, 2023 15:07
-
-
Save BuonOmo/f415466c4af38f236c11d879099af7cf to your computer and use it in GitHub Desktop.
Delete all items in a dynamo db table
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
#!/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 |
@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!)
Thank you for sharing this script. Does it really delete all items, or just the first 1000 max (or 1MB worth of data)?
@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
just a small suggestion if you have more than one option