Search code examples
amazon-dynamodbdynamodb-queries

DynamoDB for listing all items in the table using GSI


I have a table like this in dynamodb

name(PK) key(SK) description
read user Read User
read account Read Account
write user Write User

I want to list all data from the table, but I don't want to perform a scan on the table. So I added an index on the table allIndex. It's value will always be same(all in example)

name(PK) key(SK) description allIndex
read user Read User all
read account Read Account all
write user Write User all

Now I can query using allIndex to list all data from a table. It's benefit would be all data will reside in the same partition in dynamodb's GSI. I wanted to know if this is a good idea to do so? or will it lead to a hot partition on GSI?


Solution

  • scan is an appropriate option for your use case.

    query is preferred over scan when you are filtering a subset of the data in your application. The scan operation can be expensive because it has to read every item in your database. This is a bad idea if you're just fetching a few items. However, if your access pattern requires you to read the entire database, scan is the best option.