Skip to content

Instantly share code, notes, and snippets.

@k3karthic
Last active July 12, 2022 18:56
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save k3karthic/4bc929885eef40dbe010 to your computer and use it in GitHub Desktop.
Save k3karthic/4bc929885eef40dbe010 to your computer and use it in GitHub Desktop.
Truncate all keys in a dynamodb table
#!/bin/bash
TABLE_NAME=$1
# Get id list
aws dynamodb scan --table-name $TABLE_NAME | grep ID | awk '{ print $2 }' > /tmp/truncate.list
# Delete from id list
cat /tmp/truncate.list | xargs -IID aws dynamodb delete-item --table-name $TABLE_NAME --key '{ "id": { "S": "ID" }}'
# Remove id list
rm /tmp/truncate.list
@dalazx
Copy link

dalazx commented Sep 30, 2021

aws dynamodb scan --table-name "$TABLE_NAME" | jq -c '.Items[]' | \
    xargs -L1 -I{} -0 aws dynamodb delete-item --table-name "$TABLE_NAME" --key '{}'

See --select SPECIFIC_ATTRIBUTES in aws dynamodb scan help to tune the key.

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