In my DynamoDB table, There is HashKey = ID and GSI = Type. I need to fetch all hashKeys (IDs) for particular type (GSI).
What is the efficient way to fetch all IDs for given type in this case. My DynamoDB table won't be large.
Query the index for that type. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Querying
If you want to have only distinct values then you have to group them on client's side: Distinct attribute value from Global Secondary Index in DynamoDB
You could just query the GSI for the 'type' you're interested in and retrieve the IDs your interested in since all key field from the table are automatically projected into the GSI