Skip to content

Instantly share code, notes, and snippets.

@clemlesne
Last active August 2, 2021 10:35
Show Gist options
  • Save clemlesne/2c3eb103ebc45ca3bf6bd22fd15c40e1 to your computer and use it in GitHub Desktop.
Save clemlesne/2c3eb103ebc45ca3bf6bd22fd15c40e1 to your computer and use it in GitHub Desktop.
Wipe AWS Timestream database plus tables
#!/bin/sh
#
# Wipe all tables contained into a AWS Timestream database.
# Usage: wipe-timestream.sh -d [my-db]
#
# TODO: Iterate through the AWS pagination for getting more than 20 tables per script exec
#
usage() {
echo "Usage: $0 [-d]" 1>&2
exit 1
}
while getopts ":d:" arg; do
case "${arg}" in
d)
database=${OPTARG}
;;
h | *)
usage
exit 0
;;
esac
done
echo "Getting info for Timestream database ${database}..."
# List tables
tables_raw=$(aws timestream-write list-tables --database-name "${database}" --max-results 20)
for row in $(echo "${tables_raw}" | jq -r '.Tables[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
table_name=$(_jq '.TableName')
echo "Deleting table ${table_name}..."
aws timestream-write delete-table --database-name "${database}" --table-name "${table_name}"
done
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment