Jul 10, 2018

AWS CLI: How to remove all items from AWS DynamoDB by recreating tables?

A while ago I wrote about removing items from DynamoDB one by one AWS CLI: How to remove all items from AWS DynamoDB table with complex key? unfortunately it's very very very slow approach and I've found the best way: recreate tables :) Script:
(
aws_profile=your profile
LOG_DIR=logs
aws dynamodb --profile $aws_profile delete-table --table-name your-table
aws dynamodb --profile $aws_profile create-table --table-name your-table --attribute-definitions AttributeName=dataDateTime,AttributeType=S AttributeName=userId,AttributeType=S --key-schema AttributeName=userId,KeyType=HASH AttributeName=dataDateTime,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --sse-specification Enabled=true
)

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.