DynamoDB : List all partition keys

WPrathamesh picture WPrathamesh · Feb 8, 2018 · Viewed 9.1k times · Source

I want to update contains in DynamoDB, for which I need to iterate over existing partition keys present in table. Is there any way to fetch only list of partition keys using Python. Scan and Query only work on attributes of my table. Is there any way to get all partition key for table ?

Answer

Mike Dinescu picture Mike Dinescu · Feb 11, 2018

If your table uses sort keys in addition to the partition keys (stated differently, if the keys are composite of partition + sort key) then the answer is: no - there is no way to query or scan for just the partition keys. To clarify, you can still scan your table with a projection that returns the keys only, but it will return each primary key multiple times, once for each item that has the same primary key with a different sort key.

If your table schema uses partition keys only (no sort key) then you can write a scan with a projection of only the primary key and therefore, get the list of partition keys as a result.