Skip to content

Instantly share code, notes, and snippets.

@4nth0
Created August 17, 2021 09:51
Show Gist options
  • Save 4nth0/4778cf9da4259ef87bd8b9d4aa18fc1a to your computer and use it in GitHub Desktop.
Save 4nth0/4778cf9da4259ef87bd8b9d4aa18fc1a to your computer and use it in GitHub Desktop.
Scan and delete entries from Dynamodb using aws cli
#!/bin/sh
table="<table-name>"
region="<table-region>"
primary_keys="first_key"
file_target="scan-results.log"
aws dynamodb scan \
--table-name $table \
--filter-expression 'key = :key' \
--expression-attribute-values '{":key":{"N":"value"}}' \
--projection-expression "$primary_keys" \
--region $region > $file_target
echo "Scan has been finished"
echo "Scan results have been written into the file $file_target"
cat $file_target | jq -r ".Items[] | tojson" | tr '\n' '\0' | \
xargs -0 -I keyItem aws dynamodb delete-item \
--table-name $table \
--key=keyItem \
--region $region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment