Since the question is about using the query
operation, here it goes.
As the AWS cli documentation explains, you should separate the attribute values from the condition, by using the --expression-attribute-values
parameter:
aws dynamodb query --table-name Users
--key-condition-expression "Username = :v1"
--expression-attribute-values "{ \":v1\" : { \"S\" : \"test\" } }"
Additionally, you may combine more attributes in the filter (in my case I have a Datetime sort key I want to filter by):
aws dynamodb query
--table-name Users
--key-condition-expression "Username = :v1 AND #Datetime BETWEEN :v2 AND :v3"
--expression-attribute-names "{ \"#Datetime\": \"Datetime\" }"
--expression-attribute-values "{ \":v1\" : { \"S\" : \"test\" }, \":v2\" : { \"S\" : \"2019-06-06\" }, \":v3\" : { \"S\" : \"2019-06-07\" } }"
Here the #Datetime
mapping is done through the --expression-attribute-names
parameter, because Datetime
is a reserved keyword, so I cannot use it inside the key condition expression.