Skip to content

Instantly share code, notes, and snippets.

@pushplay
Last active May 28, 2024 13:51
Show Gist options
  • Save pushplay/d2cac7ca1a10a5a49f6947a02657a23a to your computer and use it in GitHub Desktop.
Save pushplay/d2cac7ca1a10a5a49f6947a02657a23a to your computer and use it in GitHub Desktop.
Delete all items (clear) in a DynamoDB table using bash
#!/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"}}'
@pushplay
Copy link
Author

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