Creating a sort key in DynamoDB on nested attributs

Viewed 22

My document in DyanamoDB follows the following structure

{
    "id": "<<GUID>>",
    "ts": <<unix_epoch>>
    "audit": {
        "lastUpdatedOn": <<unix_epoch>>
    }
}

I wan't to create a secondary GSI on this table with id as the PK and the audit.lastUpdatedOn as the SK.

Can I use a nested property as a sort key? (I tried to do it, but it didn't behave the way i wanted it to behave)

1 Answers

No, that's not allowed. DynamodBb permits only string, number and binary scalar types as keys:

Docs Each primary key attribute must be a scalar (meaning that it can hold only a single value). The only data types allowed for primary key attributes are string, number, or binary. There are no such restrictions for other, non-key attributes.

Related