I am moving my database from a sql database to Dynamodb. I currently have a table with those values:
- tenantId (PartitionKey)
- resourceId (RangeKey)
- type
- role
- name
I have the following query at the moment:
- get all the resources belonging to a tenant
ten
that has typet
, roler
and name containsn
. Wheretype
role
name
may be null values, so in that case those are not used as filters.
Using filters it is possible to make this query in dynamodb, but reading the following article https://aws.amazon.com/blogs/database/querying-on-multiple-attributes-in-amazon-dynamodb/ I realized it may be an expensive query as dynamodb is retrieving those data and then filtering server side. That page suggests to create a GSI with the following value:
- tenantId-type-role-name
With this index I can easily filter for ten
t
r
n
but in case I just have to filter for tenantId
type
name
how should I query the GSI to get all the records that have tenant ten
type t
, and name contains n
but have no restrictions on role
(contains
statement seems only to be supported on filters).
I am wondering if I need to create a GSI for each combination, something like:
- tenantId-type
- tenantId-role
- tenantId-name
- tenantId-type-role
- ...
Thanks in advance for your help