Skip to content

Instantly share code, notes, and snippets.

@vdhanan
Created March 25, 2024 17:43
Show Gist options
  • Save vdhanan/52f8fd9321dbedc3198488335bd2fd64 to your computer and use it in GitHub Desktop.
Save vdhanan/52f8fd9321dbedc3198488335bd2fd64 to your computer and use it in GitHub Desktop.
#!/bin/bash
TABLE_NAME="identity-users"
ATTRIBUTE_NAME="farcasterID"
ATTRIBUTE_VALUE="7811"
# Step 1: Scan the table and filter items based on the condition
KEYS=$(aws dynamodb scan \
--table-name "$TABLE_NAME" \
--filter-expression "farcasterID = :val" \
--expression-attribute-values '{":val":{"S":"'"$ATTRIBUTE_VALUE"'"}}' \
--query "Items[].userID.S" \
--output text)
# Step 2: Iterate over the keys and remove the attribute for each item
for KEY in $KEYS; do
aws dynamodb update-item \
--table-name "$TABLE_NAME" \
--key '{"userID": {"S": "'"$KEY"'"}}' \
--update-expression "REMOVE $ATTRIBUTE_NAME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment