0

So I have below rows in DynamoDB with example data. I want to find out the count in below format which means given a file name as input, output should be the number of events of that file present in the DB. Currently I have created a GSI on eventId as rangekey and filename as hashkey. I am doing query and pagination to get the count but its very slow due to number of rows in millions. Is there any other faster way to do it since I need to find only the count and not individual items.

fileName BrandCode Eventid
ABC       123       30100
ABC       367       30100
ABC       891       30111
XYZ       456       40758
XYZ       298       40759
XYZ       296       30111

Basically a file can generate multiple events and each event can be split into multiple Brandcodes.

FileName Count of events

ABC      2

XYZ      3
ghostrider
  • 2,046
  • 3
  • 23
  • 46
  • Does this answer your question? [How to get group by and count of millions of records in fastest way in dynamodb](https://stackoverflow.com/questions/75471575/how-to-get-group-by-and-count-of-millions-of-records-in-fastest-way-in-dynamodb) – Charles Feb 20 '23 at 22:30

1 Answers1

1

Ideally you want to avoid doing a Query and paginating all of the data each time you need a count of the items. I explain in this SO answer how to overcome that by using DynamoDB Streams and an aggregation window to create an easy to query count item, which you can retrieve with a single GetItem call, which is fast and efficient.

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31