3
votes

I have a dynamoDB table with two attributes:


A: primary partition key

B: primary sort key


I want to query this table using attribute B since I don't know the value of A. Is it possible to do so?

Is it possible to make B as GSI (global secondary index), how to do and query the table using B, since B is already a sort key.

1
same issue for me.thanksJayani Sumudini

1 Answers

5
votes

You need partition-key to query - you can't do it using sort-key alone. You can only scan.

So, the only way out for you is to create a GSI with B as the partition-key.

Update

Yes, you can use range-key as GSI.

The drawback to using GSI are:

  • There can only be a maximum of 5 GSI per table, so choose wisely what you need to index as GSI can only be specified during table creation and cannot be altered.
  • GSI will cost you additional money as you will need to assign Provisioned Throughput to it.
  • GSI is eventually consistent, meaning that DynamoDB does not guarantee that the moment data associated to the table's hash key is written into DB, the data's GSI hash key immediately becomes available for querying. The document states that this is usually immediate, but can be the case that it could take up to seconds for the GSI hash key to become available.