Jun 28, 2018

AWS CLI: How to remove all items from AWS DynamoDB table with complex key?

I have Dynamo table and need to clean up it with AWS CLI (on Ubuntu 16.04 or Windows 10 Pro Linux Subsystem). I couldn't find examples about this topic and decided to share my findings.
First of all I have Primary Key "userId", and the sort key is "dataDateTime". To transform JSON I'm using JQ tool.
aws dynamodb scan --table-name dev-data-table --attributes-to-get "userId" "dataDateTime" | jq .Items[] -c | xargs -t -0 -d '\n' -I keyvalue aws dynamodb delete-item --table-name dev-data-table --key ''keyvalue''
Be careful, this method is very slow, up to 10K items.
Have a good day.

1 comment: