Last active
May 28, 2024 13:51
-
-
Save pushplay/d2cac7ca1a10a5a49f6947a02657a23a to your computer and use it in GitHub Desktop.
Delete all items (clear) in a DynamoDB table using bash
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/bash | |
TABLE_NAME=TableName | |
KEY=id | |
aws dynamodb scan --table-name $TABLE_NAME --attributes-to-get "$KEY" --query "Items[].id.S" --output text | tr "\t" "\n" | xargs -t -I keyvalue aws dynamodb delete-item --table-name $TABLE_NAME --key '{"id": {"S": "keyvalue"}}' |
That should be doable. Starting from @OtterFlip's work you'll want to replace the "dynamodb scan" with "dynamodb query" and add a "--key-condition-expression" to specify the value of your PK. Check out the docs for details on that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way I can delete all items with different sort keys but the same PK?