Created
August 17, 2021 09:51
-
-
Save 4nth0/4778cf9da4259ef87bd8b9d4aa18fc1a to your computer and use it in GitHub Desktop.
Scan and delete entries from Dynamodb using aws cli
This file contains hidden or 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/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