-
-
Save toshke/d972b56c6273639ace5f62361e1ffac1 to your computer and use it in GitHub Desktop.
Truncate all keys in a dynamodb 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
#!/bin/bash | |
#### | |
#### Delete (remove) all items from Aws Dynamo DB table, by specifing table name and primary key | |
#### | |
#### Forked from https://gist.github.com/k3karthic/4bc929885eef40dbe010 | |
#### | |
#### Usage: | |
#### clean-dynamo-table TABLE_NAME PRIMARY_KEY | |
#### | |
set -e | |
TABLE_NAME=$1 | |
KEY_NAME=$2 | |
# Get id list | |
aws dynamodb scan --table-name $TABLE_NAME | jq ".Items[].$KEY_NAME.S" > "/tmp/dynamo_${TABLE_NAME}_keys.txt" | |
ALL_KEYS=$(cat "/tmp/dynamo_${TABLE_NAME}_keys.txt") | |
# Delete from id list | |
for key in $ALL_KEYS;do | |
echo "Deleting $key from $TABLE_NAME..." | |
aws dynamodb delete-item --table-name $TABLE_NAME --key "{ \"$KEY_NAME\": { \"S\": $key }}" | |
done | |
# Remove id list | |
rm "/tmp/dynamo_${TABLE_NAME}_keys.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for making this and sharing! I built on yours to be able to delete only rows with a given Partition Key prefix and Sort Key
I think this would help @howdyhyber
https://gist.github.com/michaelrios/05dbf08efeb2efab86f12013bcb1129f