-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathqueryfilter.sh
executable file
·40 lines (28 loc) · 957 Bytes
/
queryfilter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
REGION=us-east-1
TABLENAME=ShoppingCart
ARG1="$1"
ARG2="$2"
# ENDPOINTURL=http://localhost:8000
ENDPOINTURL=https://dynamodb.$REGION.amazonaws.com
PK=$ARG1
PRODUCTNAME=$ARG2
if [ -z "$ARG2" ]
then
PRODUCTNAME="Orange"
if [ -z "$ARG1" ]
then
PK="Cart1"
echo Querying $TABLENAME for Partition Key $PK and filtering on $PRODUCTNAME
fi
fi
aws dynamodb query --region $REGION --endpoint-url $ENDPOINTURL \
--table-name $TABLENAME \
--key-condition-expression "#p = :p" \
--filter-expression "#s = :s" \
--expression-attribute-names '{"#p": "PK", "#s": "ProductName" }' \
--expression-attribute-values '{":p" : {"S":"'$PK'"}, ":s" : {"S":"'$PRODUCTNAME'"}}' \
--return-consumed-capacity 'TOTAL' \
--output json \
--query '{"Scanned Count":ScannedCount, "Returned Count":Count, "Consumed RCUs ":ConsumedCapacity.CapacityUnits}' \
# --query 'Items[*][PK,SK]'