Skip to content

Instantly share code, notes, and snippets.

@jmacqueen
Last active September 15, 2016 12:10
Show Gist options
  • Save jmacqueen/455dd328d590214c25730fd4a8f64e92 to your computer and use it in GitHub Desktop.
Save jmacqueen/455dd328d590214c25730fd4a8f64e92 to your computer and use it in GitHub Desktop.
Helper bash script for AWS command line DockerDB scan counts
#!/bin/bash
case $1 in
help)
echo 'usage: dyncount <table> <column> <"="|"<>"|"<"|"<="|">"|">="> <type> <value>';
echo 'example: ./dyncount user firstName "=" S Gary';
echo '';
echo 'usage: dyncount <table> <column> <attribute_exists|attribute_not_exists>';
echo 'example: ./dyncount user firstName attribute_exists';
echo '';
echo 'usage: dyncount <table> <column> <begins_with|contains|attribute_type> <string>';
echo 'example: ./dyncount user firstName contains Gary';
echo '';
echo 'usage: dyncount <table> <column> BETWEEN <type> <value1> AND <value2>';
echo 'example: ./dyncount term sectionCount BETWEEN N 0 AND 5';
;;
esac;
case $3 in
"="|"<>"|"<"|"<="|">"|">=")
aws dynamodb scan --table-name $1 --select "COUNT" --filter-expression "$2 $3 :a" --expression-attribute-values "{\":a\" : {\"$4\" : \"$5\"}}";
;;
attribute_exists|attribute_not_exists)
aws dynamodb scan --table-name $1 --select "COUNT" --filter-expression "$3($2)";
;;
begins_with|contains|attribute_type)
aws dynamodb scan --table-name $1 --select "COUNT" --filter-expression "$3($2, :a)" --expression-attribute-values "{\":a\" : {\"S\" : \"$4\"}}";
;;
BETWEEN)
aws dynamodb scan --table-name $1 --select "COUNT" --filter-expression "$2 BETWEEN :a AND :b" --expression-attribute-values "{\":a\" : {\"$4\" : \"$5\"}, \":b\" : {\"$4\" : \"$7\"}}";
;;
esac;
# other conditionals that would be harder to script for so I'm not soing it right now
# | operand BETWEEN operand AND operand
# | operand IN ( operand (',' operand (, ...) ))
# | condition AND condition
# | condition OR condition
# | NOT condition
# | ( condition )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment