I'm doing a small serverless todo app and I created a GSI in an empty table in the dynamo GUI, the table has a PK = id
and SK = userId
with the GSI PK = gsi1pk
which is a combo of the userId and todo and SK = status
.
I've added items using my api with this schema in the code
Item: {
id: { S: uuidv4() },
userId: { S: todo.userId },
title: { S: todo.title },
description: { S: todo.description },
createdAt: { S: currentDate.toISOString() },
status: { S: todo.status },
entityType: { S: 'todo' },
gsi1pk: { S: `${todo.userId}#todo` }
}
with the API request being
{
"userId": "emma1",
"title": "Schedule gym session",
"description": "Book a workout session with a personal trainer",
"createdAt": "2023-05-26T11:45:00Z",
"status": "pending",
"entityType": "todo"
}
And my GSI is still saying my item count is zero? What have I done wrong?
Your GSI is saying your item count is 0 because you only created it, the count is only updated every 6 hours.
To do a live count, do a Scan
with Select=COUNT
to retrieve an accurate count.
aws dynamodb scan \
--table-name myTable \
--index-name myIndex \
--select COUNT
If you are still seeing no items, then ensure