I've got a Dynamo table storing documents that look like this:
{
"guid": "<some UUID>"
"created_at": 1550778260030,
"display_name": "person",
"updated_at": 1550778260030,
"info": {
"locked": false,
"confirmed": true,
"deactivated": false,
"email": "person@example.com"
}
}
The table has a Global Secondary Index managed by Terraform defined as such:
global_secondary_index {
name = "display_name_index"
hash_key = "display_name"
projection_type = "INCLUDE"
non_key_attributes = [
"updated_at",
"info.email",
"created_at"
]
}
However when I query the table the info.email
field isn't returned:
aws dynamodb query \
--table-name "accounts" \
--index-name "display_name_index" \
--key-condition-expression "display_name = :display_name" \
--expression-attribute-values '{":display_name":{"S":"person"}}'
{
"Count": 1,
"Items": [
{
"created_at": {
"N": "1550778260030"
},
"display_name": {
"S": "person"
}
"updated_at": {
"N": "1550778260030"
}
}
],
"ScannedCount": 1,
"ConsumedCapacity": null
}
If I change the non_key_attributes
to include info
it returns the full info blob just fine, and I can use a projection-expression
of info.email
to retrieve that field just fine:
{
"Count": 1,
"Items": [
{
"info": {
"M": {
"email": {
"S": "person@example.com"
}
}
}
}
],
"ScannedCount": 1,
"ConsumedCapacity": null
}
The Dynamo docs do specify that index keys have to be top-level, but they don't mention anything about non-key attributes in a projection having to be top-level. Therefore I'd assume that anything that works in a projection-expression should work in an index projection, but that seems to not be the case?
Am I doing something wrong with this index definition or the query? Or does Dynamo just not support nested non-key attributes as part of an index's projection?