I have a DynamoDB table with some string datatype attributes (sample below). I use the AWS CLI to download this data in my local Mac.
I want to scan/query the DynamoDB table and download all the records that match a certain condition. As I want to pull all the records that have address type = Home
, I assume that I have to use scan
, but when I issue this command I get this error:
Invalid FilterExpression : Attribute name is a reserved keyword; reserved keyword: type.
aws dynamodb scan--table-name my_table \
--filter-expression "type = :address_type" \
--expression-attribute-values '{":address_type: {"S": "Home"}}'
id | name | address | type
john | doe | 123 pearl st | Home
....
I've tried without the filter expression and the command works.
Invalid FilterExpression : Attribute name is a reserved keyword; reserved keyword: type.
Unforunately, you've used a reserved word, type
, as an attribute name. But don't worry, all is not lost. It's a little more cumbersome to handle reserved attribute names, but not too bad.
Just like the value :address_type
in the filter expression is a placeholder for an attribute value defined in --expression-attribute-values
, #type
can be a placeholder for an attribute name defined in --expression-attribute-names
.
aws dynamodb scan --table-name my_table \
--filter-expression "#type = :address_type" \
--expression-attribute-values '{":address_type: {"S": "Home"}}' \
--expression-attribute-names '{"#type": "type"}'