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.

JQ: How to install JQ 1.5 in Ubuntu?

JQ is a great JSON Query tool. More info about the tool you find at the site https://stedolan.github.io/jq/.

In Ubuntu 16.04 you can install jq 1.3 by running command:
sudo apt-get install jq
To install jq 1.5 you can run the command below:
curl -O -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x jq-linux64
sudo mv jq-linux64 /usr/bin/jq
Have a good day.